1 // (C) Copyright Ion Gaztanaga 2014.
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).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_IS_COPY_ASSIGNABLE_HPP_INCLUDED
10 #define BOOST_TT_IS_COPY_ASSIGNABLE_HPP_INCLUDED
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>
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>
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>
31 // should be the last #include
32 #include <boost/type_traits/detail/bool_trait_def.hpp>
38 template <bool DerivedFromNoncopyable, class T>
39 struct is_copy_assignable_impl2 {
41 // Intel compiler has problems with SFINAE for copy constructors and deleted functions:
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);
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;
54 static decltype(::boost::declval<U&>() = ::boost::declval<const U&>(), yes_type() ) test(int);
57 static no_type test(...);
59 static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
62 static BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type produce();
65 static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
67 static boost::type_traits::yes_type test(...);
68 // If you see errors like this:
70 // `'T::operator=(const T&)' is private`
71 // `boost/type_traits/is_copy_assignable.hpp:NN:M: error: within this context`
73 // then you are trying to call that macro for a structure defined like that:
78 // T & operator=(const T &);
82 // To fix that you must modify your structure:
84 // // C++03 and C++11 version
85 // struct T: private boost::noncopyable {
88 // T & operator=(const T &);
96 // T& operator=(const T &) = delete;
99 BOOST_STATIC_CONSTANT(bool, value = (
100 sizeof(test(produce())) == sizeof(boost::type_traits::yes_type)
106 struct is_copy_assignable_impl2<true, T> {
107 BOOST_STATIC_CONSTANT(bool, value = false);
111 struct is_copy_assignable_impl {
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
125 BOOST_STATIC_CONSTANT(bool, value = (
126 boost::detail::is_copy_assignable_impl2<
127 boost::is_base_and_derived<boost::noncopyable, T>::value,T
133 } // namespace detail
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)
145 #include <boost/type_traits/detail/bool_trait_undef.hpp>
147 #endif // BOOST_TT_IS_COPY_ASSIGNABLE_HPP_INCLUDED