1 // (C) Copyright Antony Polukhin 2013.
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).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED
10 #define BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED
12 #include <boost/config.hpp>
13 #include <boost/type_traits/detail/yes_no_type.hpp>
14 #include <boost/type_traits/is_base_and_derived.hpp>
15 #include <boost/type_traits/add_reference.hpp>
16 #include <boost/type_traits/is_rvalue_reference.hpp>
17 #include <boost/utility/declval.hpp>
18 #include <boost/noncopyable.hpp>
20 // should be the last #include
21 #include <boost/type_traits/detail/bool_trait_def.hpp>
27 template <bool DerivedFromNoncopyable, class T>
28 struct is_copy_constructible_impl2 {
30 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
32 // error: function *function_name* cannot be referenced -- it is a deleted function
33 // static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
35 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION)
37 #ifdef BOOST_NO_CXX11_DECLTYPE
39 static boost::type_traits::yes_type test(T1&, boost::mpl::int_<sizeof(T1(boost::declval<T1&>()))>* = 0);
42 static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
45 static boost::type_traits::no_type test(...);
48 static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
49 static boost::type_traits::yes_type test(...);
52 // If you see errors like this:
54 // `'T::T(const T&)' is private`
55 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
57 // then you are trying to call that macro for a structure defined like that:
66 // To fix that you must modify your structure:
68 // // C++03 and C++11 version
69 // struct T: private boost::noncopyable {
80 // T(const T &) = delete;
83 BOOST_STATIC_CONSTANT(bool, value = (
85 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type>()
86 )) == sizeof(boost::type_traits::yes_type)
88 boost::is_rvalue_reference<T>::value
93 struct is_copy_constructible_impl2<true, T> {
94 BOOST_STATIC_CONSTANT(bool, value = false);
98 struct is_copy_constructible_impl {
100 BOOST_STATIC_CONSTANT(bool, value = (
101 boost::detail::is_copy_constructible_impl2<
102 boost::is_base_and_derived<boost::noncopyable, T>::value,
108 } // namespace detail
110 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_constructible,T,::boost::detail::is_copy_constructible_impl<T>::value)
111 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void,false)
112 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
113 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const,false)
114 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const volatile,false)
115 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void volatile,false)
120 #include <boost/type_traits/detail/bool_trait_undef.hpp>
122 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED