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);
36 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
37 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
38 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION) && !(defined(BOOST_MSVC) && _MSC_VER == 1800)
40 #ifdef BOOST_NO_CXX11_DECLTYPE
42 static boost::type_traits::yes_type test(T1&, boost::mpl::int_<sizeof(T1(boost::declval<T1&>()))>* = 0);
45 static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
48 static boost::type_traits::no_type test(...);
51 static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
52 static boost::type_traits::yes_type test(...);
55 // If you see errors like this:
57 // `'T::T(const T&)' is private`
58 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
60 // then you are trying to call that macro for a structure defined like that:
69 // To fix that you must modify your structure:
71 // // C++03 and C++11 version
72 // struct T: private boost::noncopyable {
83 // T(const T &) = delete;
86 BOOST_STATIC_CONSTANT(bool, value = (
88 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type>()
89 )) == sizeof(boost::type_traits::yes_type)
91 boost::is_rvalue_reference<T>::value
96 struct is_copy_constructible_impl2<true, T> {
97 BOOST_STATIC_CONSTANT(bool, value = false);
101 struct is_copy_constructible_impl {
103 BOOST_STATIC_CONSTANT(bool, value = (
104 boost::detail::is_copy_constructible_impl2<
105 boost::is_base_and_derived<boost::noncopyable, T>::value,
111 } // namespace detail
113 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_constructible,T,::boost::detail::is_copy_constructible_impl<T>::value)
114 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void,false)
115 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
116 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const,false)
117 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const volatile,false)
118 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void volatile,false)
123 #include <boost/type_traits/detail/bool_trait_undef.hpp>
125 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED