]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/has_new_operator.hpp
update to boost 1.41.0
[lyx.git] / boost / boost / type_traits / has_new_operator.hpp
1 \r
2 //  (C) Copyright Runar Undheim, Robert Ramey & John Maddock 2008.\r
3 //  Use, modification and distribution are subject to the Boost Software License,\r
4 //  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at\r
5 //  http://www.boost.org/LICENSE_1_0.txt).\r
6 //\r
7 //  See http://www.boost.org/libs/type_traits for most recent version including documentation.\r
8 \r
9 #ifndef BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED\r
10 #define BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED\r
11 \r
12 #include <new> // std::nothrow_t\r
13 #include <cstddef> // std::size_t\r
14 #include <boost/type_traits/config.hpp>\r
15 #include <boost/type_traits/detail/yes_no_type.hpp>\r
16 #include <boost/type_traits/detail/ice_or.hpp>\r
17 \r
18 // should be the last #include\r
19 #include <boost/type_traits/detail/bool_trait_def.hpp>\r
20 \r
21 namespace boost {\r
22 namespace detail {\r
23     template <class U, U x> \r
24     struct test;\r
25 \r
26     template <typename T>\r
27     struct has_new_operator_impl {\r
28         template<class U>\r
29         static type_traits::yes_type check_sig(\r
30             U*, \r
31             test<\r
32             void *(*)(std::size_t),\r
33                 &U::operator new\r
34             >* = NULL\r
35         );\r
36         template<class U>\r
37         static type_traits::yes_type check_sig(\r
38             U*, \r
39             test<\r
40             void *(*)(std::size_t, const std::nothrow_t&),\r
41                 &U::operator new\r
42             >* = NULL\r
43         );\r
44         template<class U>\r
45         static type_traits::yes_type check_sig(\r
46             U*, \r
47             test<\r
48             void *(*)(std::size_t, void*),\r
49                 &U::operator new\r
50             >* = NULL\r
51         );\r
52         template<class U>\r
53         static type_traits::no_type check_sig(...);\r
54 \r
55         template<class U>\r
56         static type_traits::yes_type check_sig2(\r
57             U*, \r
58             test<\r
59             void *(*)(std::size_t),\r
60                 &U::operator new[]\r
61             >* = NULL\r
62         );\r
63         template<class U>\r
64         static type_traits::yes_type check_sig2(\r
65             U*, \r
66             test<\r
67             void *(*)(std::size_t, const std::nothrow_t&),\r
68                 &U::operator new[]\r
69             >* = NULL\r
70         );\r
71         template<class U>\r
72         static type_traits::yes_type check_sig2(\r
73             U*, \r
74             test<\r
75             void *(*)(std::size_t, void*),\r
76                 &U::operator new[]\r
77             >* = NULL\r
78         );\r
79         template<class U>\r
80         static type_traits::no_type check_sig2(...);\r
81 \r
82         // GCC2 won't even parse this template if we embed the computation\r
83         // of s1 in the computation of value.\r
84         #ifdef __GNUC__\r
85             BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl<T>::template check_sig<T>(0)));\r
86             BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl<T>::template check_sig2<T>(0)));\r
87         #else\r
88             #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)\r
89                 #pragma warning(push)\r
90                 #pragma warning(disable:6334)\r
91             #endif\r
92 \r
93             BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig<T>(0)));\r
94             BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2<T>(0)));\r
95 \r
96             #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)\r
97                 #pragma warning(pop)\r
98             #endif\r
99         #endif\r
100         BOOST_STATIC_CONSTANT(bool, value = \r
101            (::boost::type_traits::ice_or<\r
102             (s1 == sizeof(type_traits::yes_type)),\r
103             (s2 == sizeof(type_traits::yes_type))\r
104            >::value)\r
105         );\r
106     };\r
107 } // namespace detail\r
108 \r
109 BOOST_TT_AUX_BOOL_TRAIT_DEF1(has_new_operator,T,::boost::detail::has_new_operator_impl<T>::value)\r
110 \r
111 } // namespace boost\r
112 \r
113 #include <boost/type_traits/detail/bool_trait_undef.hpp>\r
114 \r
115 #endif // BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED\r