Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / type_traits / is_copy_constructible.hpp
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/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>
19
20 // should be the last #include
21 #include <boost/type_traits/detail/bool_trait_def.hpp>
22
23 namespace boost {
24
25 namespace detail{
26
27 template <bool DerivedFromNoncopyable, class T>
28 struct is_copy_constructible_impl2 {
29
30 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
31 //
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);
34 //                                                        ^ 
35 //
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)
39
40 #ifdef BOOST_NO_CXX11_DECLTYPE
41     template <class T1>
42     static boost::type_traits::yes_type test(T1&, boost::mpl::int_<sizeof(T1(boost::declval<T1&>()))>* = 0);
43 #else
44     template <class T1>
45     static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
46 #endif
47
48     static boost::type_traits::no_type test(...);
49 #else
50     template <class T1>
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(...);
53 #endif
54
55     // If you see errors like this:
56     //
57     //      `'T::T(const T&)' is private`
58     //      `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
59     //
60     // then you are trying to call that macro for a structure defined like that:
61     //
62     //      struct T {
63     //          ...
64     //      private:
65     //          T(const T &);
66     //          ...
67     //      };
68     //
69     // To fix that you must modify your structure:
70     //
71     //      // C++03 and C++11 version
72     //      struct T: private boost::noncopyable {
73     //          ...
74     //      private:
75     //          T(const T &);
76     //          ...
77     //      };
78     //
79     //      // C++11 version
80     //      struct T {
81     //          ...
82     //      private:
83     //          T(const T &) = delete;
84     //          ...
85     //      };
86     BOOST_STATIC_CONSTANT(bool, value = (
87             sizeof(test(
88                 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type>()
89             )) == sizeof(boost::type_traits::yes_type)
90         ||
91             boost::is_rvalue_reference<T>::value
92     ));
93 };
94
95 template <class T>
96 struct is_copy_constructible_impl2<true, T> {
97     BOOST_STATIC_CONSTANT(bool, value = false);
98 };
99
100 template <class T>
101 struct is_copy_constructible_impl {
102
103     BOOST_STATIC_CONSTANT(bool, value = (
104         boost::detail::is_copy_constructible_impl2<
105             boost::is_base_and_derived<boost::noncopyable, T>::value,
106             T
107         >::value
108     ));
109 };
110
111 } // namespace detail
112
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)
119 #endif
120
121 } // namespace boost
122
123 #include <boost/type_traits/detail/bool_trait_undef.hpp>
124
125 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED