blob: b437ee9fc8afe67d4de12e1db7f98d113a18bcc8 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
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 <ndnboost/type_traits/config.hpp>
15#include <ndnboost/type_traits/detail/yes_no_type.hpp>
16#include <ndnboost/type_traits/detail/ice_or.hpp>
17
18// should be the last #include
19#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
20
21namespace ndnboost {
22namespace 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_sig1(
30 U*,
31 test<
32 void *(*)(std::size_t),
33 &U::operator new
34 >* = NULL
35 );
36 template<class U>
37 static type_traits::no_type check_sig1(...);
38
39 template<class U>
40 static type_traits::yes_type check_sig2(
41 U*,
42 test<
43 void *(*)(std::size_t, const std::nothrow_t&),
44 &U::operator new
45 >* = NULL
46 );
47 template<class U>
48 static type_traits::no_type check_sig2(...);
49
50 template<class U>
51 static type_traits::yes_type check_sig3(
52 U*,
53 test<
54 void *(*)(std::size_t, void*),
55 &U::operator new
56 >* = NULL
57 );
58 template<class U>
59 static type_traits::no_type check_sig3(...);
60
61
62 template<class U>
63 static type_traits::yes_type check_sig4(
64 U*,
65 test<
66 void *(*)(std::size_t),
67 &U::operator new[]
68 >* = NULL
69 );
70 template<class U>
71 static type_traits::no_type check_sig4(...);
72
73 template<class U>
74 static type_traits::yes_type check_sig5(
75 U*,
76 test<
77 void *(*)(std::size_t, const std::nothrow_t&),
78 &U::operator new[]
79 >* = NULL
80 );
81 template<class U>
82 static type_traits::no_type check_sig5(...);
83
84 template<class U>
85 static type_traits::yes_type check_sig6(
86 U*,
87 test<
88 void *(*)(std::size_t, void*),
89 &U::operator new[]
90 >* = NULL
91 );
92 template<class U>
93 static type_traits::no_type check_sig6(...);
94
95 // GCC2 won't even parse this template if we embed the computation
96 // of s1 in the computation of value.
97 #ifdef __GNUC__
98 BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl<T>::template check_sig1<T>(0)));
99 BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl<T>::template check_sig2<T>(0)));
100 BOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(has_new_operator_impl<T>::template check_sig3<T>(0)));
101 BOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(has_new_operator_impl<T>::template check_sig4<T>(0)));
102 BOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(has_new_operator_impl<T>::template check_sig5<T>(0)));
103 BOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(has_new_operator_impl<T>::template check_sig6<T>(0)));
104 #else
105 #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)
106 #pragma warning(push)
107 #pragma warning(disable:6334)
108 #endif
109
110 BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig1<T>(0)));
111 BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2<T>(0)));
112 BOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(check_sig3<T>(0)));
113 BOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(check_sig4<T>(0)));
114 BOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(check_sig5<T>(0)));
115 BOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(check_sig6<T>(0)));
116
117 #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)
118 #pragma warning(pop)
119 #endif
120 #endif
121 BOOST_STATIC_CONSTANT(bool, value =
122 (::ndnboost::type_traits::ice_or<
123 (s1 == sizeof(type_traits::yes_type)),
124 (s2 == sizeof(type_traits::yes_type)),
125 (s3 == sizeof(type_traits::yes_type)),
126 (s4 == sizeof(type_traits::yes_type)),
127 (s5 == sizeof(type_traits::yes_type)),
128 (s6 == sizeof(type_traits::yes_type))
129 >::value)
130 );
131 };
132} // namespace detail
133
134BOOST_TT_AUX_BOOL_TRAIT_DEF1(has_new_operator,T,::ndnboost::detail::has_new_operator_impl<T>::value)
135
136} // namespace ndnboost
137
138#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
139
140#endif // BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED