blob: 099c1f2821c15dee6e94c5f87b4e94a204ea0b05 [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -07009#ifndef NDNBOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED
10#define NDNBOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -070011
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__
Jeff Thompson3d613fd2013-10-15 15:39:04 -070098 NDNBOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl<T>::template check_sig1<T>(0)));
99 NDNBOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl<T>::template check_sig2<T>(0)));
100 NDNBOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(has_new_operator_impl<T>::template check_sig3<T>(0)));
101 NDNBOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(has_new_operator_impl<T>::template check_sig4<T>(0)));
102 NDNBOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(has_new_operator_impl<T>::template check_sig5<T>(0)));
103 NDNBOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(has_new_operator_impl<T>::template check_sig6<T>(0)));
Jeff Thompsona28eed82013-08-22 16:21:10 -0700104 #else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105 #if NDNBOOST_WORKAROUND(NDNBOOST_MSVC_FULL_VER, >= 140050000)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700106 #pragma warning(push)
107 #pragma warning(disable:6334)
108 #endif
109
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700110 NDNBOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig1<T>(0)));
111 NDNBOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2<T>(0)));
112 NDNBOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(check_sig3<T>(0)));
113 NDNBOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(check_sig4<T>(0)));
114 NDNBOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(check_sig5<T>(0)));
115 NDNBOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(check_sig6<T>(0)));
Jeff Thompsona28eed82013-08-22 16:21:10 -0700116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117 #if NDNBOOST_WORKAROUND(NDNBOOST_MSVC_FULL_VER, >= 140050000)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700118 #pragma warning(pop)
119 #endif
120 #endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121 NDNBOOST_STATIC_CONSTANT(bool, value =
Jeff Thompsona28eed82013-08-22 16:21:10 -0700122 (::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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700134NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(has_new_operator,T,::ndnboost::detail::has_new_operator_impl<T>::value)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700135
136} // namespace ndnboost
137
138#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
139
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700140#endif // NDNBOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED