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_noncopyable.hpp>
47 template <class T, bool b> struct is_copy_constructible_imp : public boost::is_constructible<T, const T&>{};
48 template <class T> struct is_copy_constructible_imp<T, true> : public false_type{};
52 template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_noncopyable<T>::value>{};
54 template <> struct is_copy_constructible<void> : public false_type{};
55 template <> struct is_copy_constructible<void const> : public false_type{};
56 template <> struct is_copy_constructible<void const volatile> : public false_type{};
57 template <> struct is_copy_constructible<void volatile> : public false_type{};
65 #include <boost/type_traits/detail/yes_no_type.hpp>
66 #include <boost/type_traits/is_noncopyable.hpp>
67 #include <boost/type_traits/add_reference.hpp>
68 #include <boost/type_traits/is_rvalue_reference.hpp>
69 #include <boost/type_traits/declval.hpp>
70 #include <boost/type_traits/is_array.hpp>
71 #include <boost/type_traits/declval.hpp>
75 #pragma warning(disable:4181)
82 template <bool DerivedFromNoncopyable, class T>
83 struct is_copy_constructible_impl2 {
85 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
87 // error: function *function_name* cannot be referenced -- it is a deleted function
88 // static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
91 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
92 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
93 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION) && !(defined(BOOST_MSVC) && _MSC_VER == 1800)
95 #ifdef BOOST_NO_CXX11_DECLTYPE
97 static boost::type_traits::yes_type test(const T1&, boost::mpl::int_<sizeof(T1(boost::declval<const T1&>()))>* = 0);
100 static boost::type_traits::yes_type test(const T1&, decltype(T1(boost::declval<const T1&>()))* = 0);
103 static boost::type_traits::no_type test(...);
106 static boost::type_traits::no_type test(const T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
107 static boost::type_traits::yes_type test(...);
110 // If you see errors like this:
112 // `'T::T(const T&)' is private`
113 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
115 // then you are trying to call that macro for a structure defined like that:
124 // To fix that you must modify your structure:
126 // // C++03 and C++11 version
127 // struct T: private boost::noncopyable {
138 // T(const T &) = delete;
141 BOOST_STATIC_CONSTANT(bool, value = (
143 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T const>::type>()
144 )) == sizeof(boost::type_traits::yes_type)
146 !boost::is_rvalue_reference<T>::value
147 && !boost::is_array<T>::value
152 struct is_copy_constructible_impl2<true, T> {
153 BOOST_STATIC_CONSTANT(bool, value = false);
157 struct is_copy_constructible_impl {
159 BOOST_STATIC_CONSTANT(bool, value = (
160 boost::detail::is_copy_constructible_impl2<
161 boost::is_noncopyable<T>::value,
167 } // namespace detail
169 template <class T> struct is_copy_constructible : public integral_constant<bool, ::boost::detail::is_copy_constructible_impl<T>::value>{};
170 template <> struct is_copy_constructible<void> : public false_type{};
171 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
172 template <> struct is_copy_constructible<void const> : public false_type{};
173 template <> struct is_copy_constructible<void volatile> : public false_type{};
174 template <> struct is_copy_constructible<void const volatile> : public false_type{};
185 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED