1// (C) Copyright Antony Polukhin 2013.
2//
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_COPY_CONSTRUCTIBLE_HPP_INCLUDED
10#define BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED
11
12#include <boost/config.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, < 40900)
16
17#include <boost/type_traits/is_constructible.hpp>
18
19#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
20
21namespace boost {
22
23template <class T> struct is_copy_constructible : public boost::is_constructible<T, const T&>{};
24
25template <> struct is_copy_constructible<void> : public false_type{};
26template <> struct is_copy_constructible<void const> : public false_type{};
27template <> struct is_copy_constructible<void const volatile> : public false_type{};
28template <> struct is_copy_constructible<void volatile> : public false_type{};
29
30} // namespace boost
31
32#else
33//
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:
39//
40#include <boost/type_traits/is_noncopyable.hpp>
41
42namespace boost {
43
44 namespace detail
45 {
46
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{};
49
50 }
51
52 template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_noncopyable<T>::value>{};
53
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{};
58
59} // namespace boost
60
61#endif
62
63#else
64
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>
72
73#ifdef BOOST_MSVC
74#pragma warning(push)
75#pragma warning(disable:4181)
76#endif
77
78namespace boost {
79
80 namespace detail{
81
82 template <bool DerivedFromNoncopyable, class T>
83 struct is_copy_constructible_impl2 {
84
85 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
86 //
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);
89 // ^
90 //
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)
94
95#ifdef BOOST_NO_CXX11_DECLTYPE
96 template <class T1>
97 static boost::type_traits::yes_type test(const T1&, boost::mpl::int_<sizeof(T1(boost::declval<const T1&>()))>* = 0);
98#else
99 template <class T1>
100 static boost::type_traits::yes_type test(const T1&, decltype(T1(boost::declval<const T1&>()))* = 0);
101#endif
102
103 static boost::type_traits::no_type test(...);
104#else
105 template <class T1>
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(...);
108#endif
109
110 // If you see errors like this:
111 //
112 // `'T::T(const T&)' is private`
113 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
114 //
115 // then you are trying to call that macro for a structure defined like that:
116 //
117 // struct T {
118 // ...
119 // private:
120 // T(const T &);
121 // ...
122 // };
123 //
124 // To fix that you must modify your structure:
125 //
126 // // C++03 and C++11 version
127 // struct T: private boost::noncopyable {
128 // ...
129 // private:
130 // T(const T &);
131 // ...
132 // };
133 //
134 // // C++11 version
135 // struct T {
136 // ...
137 // private:
138 // T(const T &) = delete;
139 // ...
140 // };
141 BOOST_STATIC_CONSTANT(bool, value = (
142 sizeof(test(
143 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T const>::type>()
144 )) == sizeof(boost::type_traits::yes_type)
145 &&
146 !boost::is_rvalue_reference<T>::value
147 && !boost::is_array<T>::value
148 ));
149 };
150
151 template <class T>
152 struct is_copy_constructible_impl2<true, T> {
153 BOOST_STATIC_CONSTANT(bool, value = false);
154 };
155
156 template <class T>
157 struct is_copy_constructible_impl {
158
159 BOOST_STATIC_CONSTANT(bool, value = (
160 boost::detail::is_copy_constructible_impl2<
161 boost::is_noncopyable<T>::value,
162 T
163 >::value
164 ));
165 };
166
167 } // namespace detail
168
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{};
175#endif
176
177} // namespace boost
178
179#ifdef BOOST_MSVC
180#pragma warning(pop)
181#endif
182
183#endif
184
185#endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED
186

source code of include/boost/type_traits/is_copy_constructible.hpp