Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / type_traits / is_copy_assignable.hpp
1 //  (C) Copyright Ion Gaztanaga 2014.
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_ASSIGNABLE_HPP_INCLUDED
10 #define BOOST_TT_IS_COPY_ASSIGNABLE_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/noncopyable.hpp>
16
17 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_NO_CXX11_DECLTYPE) \
18    && !defined(BOOST_INTEL_CXX_VERSION) && \
19       !(defined(BOOST_MSVC) && _MSC_VER == 1800)
20 #define BOOST_TT_CXX11_IS_COPY_ASSIGNABLE
21 #include <boost/utility/declval.hpp>
22 #else
23    //For compilers without decltype
24    #include <boost/type_traits/is_const.hpp>
25    #include <boost/type_traits/is_array.hpp>
26    #include <boost/type_traits/add_reference.hpp>
27    #include <boost/type_traits/remove_reference.hpp>
28 #endif
29
30
31 // should be the last #include
32 #include <boost/type_traits/detail/bool_trait_def.hpp>
33
34 namespace boost {
35
36 namespace detail{
37
38 template <bool DerivedFromNoncopyable, class T>
39 struct is_copy_assignable_impl2 {
40
41 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
42 //
43 // error: function *function_name* cannot be referenced -- it is a deleted function
44 // static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
45 //                                                        ^ 
46 //
47 // MSVC 12.0 (Visual 2013) has problems when the copy constructor has been deleted. See:
48 // https://connect.microsoft.com/VisualStudio/feedback/details/800328/std-is-copy-constructible-is-broken
49 #if defined(BOOST_TT_CXX11_IS_COPY_ASSIGNABLE)
50     typedef boost::type_traits::yes_type yes_type;
51     typedef boost::type_traits::no_type  no_type;
52
53     template <class U>
54     static decltype(::boost::declval<U&>() = ::boost::declval<const U&>(), yes_type() ) test(int);
55
56     template <class>
57     static no_type test(...);
58
59     static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
60
61 #else
62     static BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type produce();
63
64     template <class T1>
65     static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
66
67     static boost::type_traits::yes_type test(...);
68     // If you see errors like this:
69     //
70     //      `'T::operator=(const T&)' is private`
71     //      `boost/type_traits/is_copy_assignable.hpp:NN:M: error: within this context`
72     //
73     // then you are trying to call that macro for a structure defined like that:
74     //
75     //      struct T {
76     //          ...
77     //      private:
78     //          T & operator=(const T &);
79     //          ...
80     //      };
81     //
82     // To fix that you must modify your structure:
83     //
84     //      // C++03 and C++11 version
85     //      struct T: private boost::noncopyable {
86     //          ...
87     //      private:
88     //          T & operator=(const T &);
89     //          ...
90     //      };
91     //
92     //      // C++11 version
93     //      struct T {
94     //          ...
95     //      private:
96     //          T& operator=(const T &) = delete;
97     //          ...
98     //      };
99     BOOST_STATIC_CONSTANT(bool, value = (
100             sizeof(test(produce())) == sizeof(boost::type_traits::yes_type)
101     ));
102    #endif
103 };
104
105 template <class T>
106 struct is_copy_assignable_impl2<true, T> {
107     BOOST_STATIC_CONSTANT(bool, value = false);
108 };
109
110 template <class T>
111 struct is_copy_assignable_impl {
112
113 #if !defined(BOOST_TT_CXX11_IS_COPY_ASSIGNABLE)
114     //For compilers without decltype, at least return false on const types, arrays
115     //types derived from boost::noncopyable and types defined as BOOST_MOVEABLE_BUT_NOT_COPYABLE
116     typedef BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type unreferenced_t;
117     BOOST_STATIC_CONSTANT(bool, value = (
118         boost::detail::is_copy_assignable_impl2<
119             boost::is_base_and_derived<boost::noncopyable, T>::value
120             || boost::is_const<unreferenced_t>::value || boost::is_array<unreferenced_t>::value
121             ,T
122         >::value
123     ));
124     #else
125     BOOST_STATIC_CONSTANT(bool, value = (
126         boost::detail::is_copy_assignable_impl2<
127             boost::is_base_and_derived<boost::noncopyable, T>::value,T
128         >::value
129     ));
130     #endif
131 };
132
133 } // namespace detail
134
135 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_assignable,T,::boost::detail::is_copy_assignable_impl<T>::value)
136 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_assignable,void,false)
137 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
138 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_assignable,void const,false)
139 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_assignable,void const volatile,false)
140 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_assignable,void volatile,false)
141 #endif
142
143 } // namespace boost
144
145 #include <boost/type_traits/detail/bool_trait_undef.hpp>
146
147 #endif // BOOST_TT_IS_COPY_ASSIGNABLE_HPP_INCLUDED