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