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