]> git.donarmstrong.com Git - rsem.git/blob - boost/type_traits/is_copy_constructible.hpp
Updated boost to v1.55.0
[rsem.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 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION)
36
37 #ifdef BOOST_NO_CXX11_DECLTYPE
38     template <class T1>
39     static boost::type_traits::yes_type test(T1&, boost::mpl::int_<sizeof(T1(boost::declval<T1&>()))>* = 0);
40 #else
41     template <class T1>
42     static boost::type_traits::yes_type test(T1&, decltype(T1(boost::declval<T1&>()))* = 0);
43 #endif
44
45     static boost::type_traits::no_type test(...);
46 #else
47     template <class T1>
48     static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0);
49     static boost::type_traits::yes_type test(...);
50 #endif
51
52     // If you see errors like this:
53     //
54     //      `'T::T(const T&)' is private`
55     //      `boost/type_traits/is_copy_constructible.hpp:68:5: error: within this context`
56     //
57     // then you are trying to call that macro for a structure defined like that:
58     //
59     //      struct T {
60     //          ...
61     //      private:
62     //          T(const T &);
63     //          ...
64     //      };
65     //
66     // To fix that you must modify your structure:
67     //
68     //      // C++03 and C++11 version
69     //      struct T: private boost::noncopyable {
70     //          ...
71     //      private:
72     //          T(const T &);
73     //          ...
74     //      };
75     //
76     //      // C++11 version
77     //      struct T {
78     //          ...
79     //      private:
80     //          T(const T &) = delete;
81     //          ...
82     //      };
83     BOOST_STATIC_CONSTANT(bool, value = (
84             sizeof(test(
85                 boost::declval<BOOST_DEDUCED_TYPENAME boost::add_reference<T>::type>()
86             )) == sizeof(boost::type_traits::yes_type)
87         ||
88             boost::is_rvalue_reference<T>::value
89     ));
90 };
91
92 template <class T>
93 struct is_copy_constructible_impl2<true, T> {
94     BOOST_STATIC_CONSTANT(bool, value = false);
95 };
96
97 template <class T>
98 struct is_copy_constructible_impl {
99
100     BOOST_STATIC_CONSTANT(bool, value = (
101         boost::detail::is_copy_constructible_impl2<
102             boost::is_base_and_derived<boost::noncopyable, T>::value,
103             T
104         >::value
105     ));
106 };
107
108 } // namespace detail
109
110 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_constructible,T,::boost::detail::is_copy_constructible_impl<T>::value)
111 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void,false)
112 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
113 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const,false)
114 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const volatile,false)
115 BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void volatile,false)
116 #endif
117
118 } // namespace boost
119
120 #include <boost/type_traits/detail/bool_trait_undef.hpp>
121
122 #endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED