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_CONSTRUCTIBLE_HPP_INCLUDED 10 #define BOOST_TT_IS_CONSTRUCTIBLE_HPP_INCLUDED 11 12 #include <boost/type_traits/integral_constant.hpp> 13 #include <boost/detail/workaround.hpp> 14 15 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) 16 17 #include <boost/type_traits/is_destructible.hpp> 18 #include <boost/type_traits/is_default_constructible.hpp> 19 #include <boost/type_traits/detail/yes_no_type.hpp> 20 #include <boost/type_traits/declval.hpp> 21 22 namespace boost{ 23 24 namespace detail{ 25 26 struct is_constructible_imp 27 { 28 template<typename T, typename ...TheArgs, typename = decltype(T(boost::declval<TheArgs>()...))> 29 static boost::type_traits::yes_type test(int); 30 template<typename, typename...> 31 static boost::type_traits::no_type test(...); 32 33 template<typename T, typename Arg, typename = decltype(::new T(boost::declval<Arg>()))> 34 static boost::type_traits::yes_type test1(int); 35 template<typename, typename> 36 static boost::type_traits::no_type test1(...); 37 38 template <typename T> 39 static boost::type_traits::yes_type ref_test(T); 40 template <typename T> 41 static boost::type_traits::no_type ref_test(...); 42 }; 43 44 } 45 46 template <class T, class ...Args> struct is_constructible : public integral_constant<bool, sizeof(detail::is_constructible_imp::test<T, Args...>(0)) == sizeof(boost::type_traits::yes_type)>{}; 47 template <class T, class Arg> struct is_constructible<T, Arg> : public integral_constant<bool, is_destructible<T>::value && sizeof(detail::is_constructible_imp::test1<T, Arg>(0)) == sizeof(boost::type_traits::yes_type)>{}; 48 template <class Ref, class Arg> struct is_constructible<Ref&, Arg> : public integral_constant<bool, sizeof(detail::is_constructible_imp::ref_test<Ref&>(boost::declval<Arg>())) == sizeof(boost::type_traits::yes_type)>{}; 49 template <class Ref, class Arg> struct is_constructible<Ref&&, Arg> : public integral_constant<bool, sizeof(detail::is_constructible_imp::ref_test<Ref&&>(boost::declval<Arg>())) == sizeof(boost::type_traits::yes_type)>{}; 50 51 template <> struct is_constructible<void> : public false_type{}; 52 template <> struct is_constructible<void const> : public false_type{}; 53 template <> struct is_constructible<void const volatile> : public false_type{}; 54 template <> struct is_constructible<void volatile> : public false_type{}; 55 56 template <class T> struct is_constructible<T> : public is_default_constructible<T>{}; 57 58 #else 59 60 #include <boost/type_traits/is_convertible.hpp> 61 #include <boost/type_traits/is_default_constructible.hpp> 62 63 namespace boost{ 64 65 // We don't know how to implement this: 66 template <class T, class U = void> struct is_constructible : public is_convertible<U, T>{}; 67 template <class T> struct is_constructible<T, void> : public is_default_constructible<T>{}; 68 template <> struct is_constructible<void, void> : public false_type{}; 69 template <> struct is_constructible<void const, void> : public false_type{}; 70 template <> struct is_constructible<void const volatile, void> : public false_type{}; 71 template <> struct is_constructible<void volatile, void> : public false_type{}; 72 template <class Ref> struct is_constructible<Ref&, void> : public false_type{}; 73 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 74 template <class Ref> struct is_constructible<Ref&&, void> : public false_type{}; 75 #endif 76 #endif 77 78 } // namespace boost 79 80 #endif // BOOST_TT_IS_CONSTRUCTIBLE_HPP_INCLUDED 81