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/detail/workaround.hpp>
15 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40900)
17 #include <boost/type_traits/is_constructible.hpp>
19 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
23 template <class T> struct is_copy_constructible : public boost::is_constructible<T, const T&>{};
25 template <> struct is_copy_constructible<void> : public false_type{};
26 template <> struct is_copy_constructible<void const> : public false_type{};
27 template <> struct is_copy_constructible<void const volatile> : public false_type{};
28 template <> struct is_copy_constructible<void volatile> : public false_type{};
34 // Special version for VC12 which has a problem when a base class (such as non_copyable) has a deleted
35 // copy constructor. In this case the compiler thinks there really is a copy-constructor and tries to
36 // instantiate the deleted member. std::is_copy_constructible has the same issue (or at least returns
37 // an incorrect value, which just defers the issue into the users code) as well. We can at least fix
38 // boost::non_copyable as a base class as a special case:
40 #include <boost/type_traits/is_base_and_derived.hpp>
41 #include <boost/noncopyable.hpp>
48 template <class T, bool b> struct is_copy_constructible_imp : public boost::is_constructible<T, const T&>{};
49 template <class T> struct is_copy_constructible_imp<T, true> : public false_type{};
53 template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_base_and_derived<boost::noncopyable, T>::value>{};
55 template <> struct is_copy_constructible<void> : public false_type{};
56 template <> struct is_copy_constructible<void const> : public false_type{};
57 template <> struct is_copy_constructible<void const volatile> : public false_type{};
58 template <> struct is_copy_constructible<void volatile> : public false_type{};
66 #include <boost/type_traits/detail/yes_no_type.hpp>
67 #include <boost/type_traits/is_base_and_derived.hpp>
68 #include <boost/type_traits/add_reference.hpp>
69 #include <boost/type_traits/is_rvalue_reference.hpp>
70 #include <boost/type_traits/declval.hpp>
71 #include <boost/type_traits/is_array.hpp>
72 #include <boost/type_traits/declval.hpp>
73 #include <boost/noncopyable.hpp>
77 #pragma warning(disable:4181)
84 template <bool DerivedFromNoncopyable, class T>
85 struct is_copy_constructible_impl2 {
87 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
89 // error: function *function_name* cannot be referenced -- it is a deleted function
90 // static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
93 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
94 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
95 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION) && !(defined(BOOST_MSVC) && _MSC_VER == 1800)
97 #ifdef BOOST_NO_CXX11_DECLTYPE
99 static boost::type_traits::yes_type test(const T1&, boost::mpl::int_<sizeof(T1(boost::declval<const T1&>()))>* = 0);
102 static boost::type_traits::yes_type test(const T1&, decltype(T1(boost::declval<const T1&>()))* = 0);
105 static boost::type_traits::no_type test(...);
108 static boost::type_traits::no_type test(const T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
109 static boost::type_traits::yes_type test(...);
112 // If you see errors like this:
114 // `'T::T(const T&)' is private`
115 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
117 // then you are trying to call that macro for a structure defined like that:
126 // To fix that you must modify your structure:
128 // // C++03 and C++11 version
129 // struct T: private boost::noncopyable {
140 // T(const T &) = delete;
143 BOOST_STATIC_CONSTANT(bool, value = (
145 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T const>::type>()
146 )) == sizeof(boost::type_traits::yes_type)
148 !boost::is_rvalue_reference<T>::value
149 && !boost::is_array<T>::value
154 struct is_copy_constructible_impl2<true, T> {
155 BOOST_STATIC_CONSTANT(bool, value = false);
159 struct is_copy_constructible_impl {
161 BOOST_STATIC_CONSTANT(bool, value = (
162 boost::detail::is_copy_constructible_impl2<
163 boost::is_base_and_derived<boost::noncopyable, T>::value,
169 } // namespace detail
171 template <class T> struct is_copy_constructible : public integral_constant<bool, ::boost::detail::is_copy_constructible_impl<T>::value>{};
172 template <> struct is_copy_constructible<void> : public false_type{};
173 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
174 template <> struct is_copy_constructible<void const> : public false_type{};
175 template <> struct is_copy_constructible<void volatile> : public false_type{};
176 template <> struct is_copy_constructible<void const volatile> : public false_type{};
187 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED