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