1
2// (C) Copyright John Maddock 2015.
3// Use, modification and distribution are subject to the Boost Software License,
4// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt).
6//
7// See http://www.boost.org/libs/type_traits for most recent version including documentation.
8
9#ifndef BOOST_TT_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED
10#define BOOST_TT_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED
11
12#include <cstddef> // size_t
13#include <boost/type_traits/integral_constant.hpp>
14#include <boost/detail/workaround.hpp>
15#include <boost/type_traits/is_complete.hpp>
16#include <boost/static_assert.hpp>
17
18#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
19#include <boost/type_traits/is_abstract.hpp>
20#endif
21#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ <= 5)) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1800))
22#include <utility> // std::pair
23#endif
24
25#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500)
26
27#include <boost/type_traits/detail/yes_no_type.hpp>
28
29namespace boost{
30
31 namespace detail{
32
33 struct is_default_constructible_imp
34 {
35 template<typename _Tp, typename = decltype(_Tp())>
36 static boost::type_traits::yes_type test(int);
37
38 template<typename>
39 static boost::type_traits::no_type test(...);
40 };
41#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
42 template<class T, bool b>
43 struct is_default_constructible_abstract_filter
44 {
45 static const bool value = sizeof(is_default_constructible_imp::test<T>(0)) == sizeof(boost::type_traits::yes_type);
46 };
47 template<class T>
48 struct is_default_constructible_abstract_filter<T, true>
49 {
50 static const bool value = false;
51 };
52#endif
53 }
54
55#if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
56 template <class T> struct is_default_constructible : public integral_constant<bool, detail::is_default_constructible_abstract_filter<T, boost::is_abstract<T>::value>::value>
57 {
58 BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_default_constructible must be complete types");
59 };
60#else
61 template <class T> struct is_default_constructible : public integral_constant<bool, sizeof(detail::is_default_constructible_imp::test<T>(0)) == sizeof(boost::type_traits::yes_type)>
62 {
63 BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_default_constructible must be complete types");
64 };
65#endif
66 template <class T, std::size_t N> struct is_default_constructible<T[N]> : public is_default_constructible<T>{};
67 template <class T> struct is_default_constructible<T[]> : public is_default_constructible<T>{};
68 template <class T> struct is_default_constructible<T&> : public integral_constant<bool, false>{};
69#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ <= 5))|| (defined(BOOST_MSVC) && (BOOST_MSVC == 1800))
70 template <class T, class U> struct is_default_constructible<std::pair<T,U> > : public integral_constant<bool, is_default_constructible<T>::value && is_default_constructible<U>::value>{};
71#endif
72#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
73 template <class T> struct is_default_constructible<T&&> : public integral_constant<bool, false>{};
74#endif
75 template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
76 template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
77 template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};
78 template <> struct is_default_constructible<void const volatile> : public integral_constant<bool, false>{};
79
80#else
81
82#include <boost/type_traits/is_pod.hpp>
83
84namespace boost{
85
86 // We don't know how to implement this, note we can not use has_trivial_constructor here
87 // because the correct implementation of that trait requires this one:
88 template <class T> struct is_default_constructible : public is_pod<T>{};
89 template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
90 template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
91 template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};
92 template <> struct is_default_constructible<void const volatile> : public integral_constant<bool, false>{};
93
94#endif
95
96} // namespace boost
97
98#endif // BOOST_TT_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED
99