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_base_and_derived.hpp>
41#include <boost/noncopyable.hpp>
42
43namespace boost {
44
45 namespace detail
46 {
47
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{};
50
51 }
52
53 template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_base_and_derived<boost::noncopyable, T>::value>{};
54
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{};
59
60} // namespace boost
61
62#endif
63
64#else
65
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>
74
75#ifdef BOOST_MSVC
76#pragma warning(push)
77#pragma warning(disable:4181)
78#endif
79
80namespace boost {
81
82 namespace detail{
83
84 template <bool DerivedFromNoncopyable, class T>
85 struct is_copy_constructible_impl2 {
86
87 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
88 //
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);
91 // ^
92 //
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)
96
97#ifdef BOOST_NO_CXX11_DECLTYPE
98 template <class T1>
99 static boost::type_traits::yes_type test(const T1&, boost::mpl::int_<sizeof(T1(boost::declval<const T1&>()))>* = 0);
100#else
101 template <class T1>
102 static boost::type_traits::yes_type test(const T1&, decltype(T1(boost::declval<const T1&>()))* = 0);
103#endif
104
105 static boost::type_traits::no_type test(...);
106#else
107 template <class T1>
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(...);
110#endif
111
112 // If you see errors like this:
113 //
114 // `'T::T(const T&)' is private`
115 // `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
116 //
117 // then you are trying to call that macro for a structure defined like that:
118 //
119 // struct T {
120 // ...
121 // private:
122 // T(const T &);
123 // ...
124 // };
125 //
126 // To fix that you must modify your structure:
127 //
128 // // C++03 and C++11 version
129 // struct T: private boost::noncopyable {
130 // ...
131 // private:
132 // T(const T &);
133 // ...
134 // };
135 //
136 // // C++11 version
137 // struct T {
138 // ...
139 // private:
140 // T(const T &) = delete;
141 // ...
142 // };
143 BOOST_STATIC_CONSTANT(bool, value = (
144 sizeof(test(
145 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T const>::type>()
146 )) == sizeof(boost::type_traits::yes_type)
147 &&
148 !boost::is_rvalue_reference<T>::value
149 && !boost::is_array<T>::value
150 ));
151 };
152
153 template <class T>
154 struct is_copy_constructible_impl2<true, T> {
155 BOOST_STATIC_CONSTANT(bool, value = false);
156 };
157
158 template <class T>
159 struct is_copy_constructible_impl {
160
161 BOOST_STATIC_CONSTANT(bool, value = (
162 boost::detail::is_copy_constructible_impl2<
163 boost::is_base_and_derived<boost::noncopyable, T>::value,
164 T
165 >::value
166 ));
167 };
168
169 } // namespace detail
170
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{};
177#endif
178
179} // namespace boost
180
181#ifdef BOOST_MSVC
182#pragma warning(pop)
183#endif
184
185#endif
186
187#endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED
188

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