Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 2 | #ifndef NDNBOOST_MPL_HAS_XXX_HPP_INCLUDED |
| 3 | #define NDNBOOST_MPL_HAS_XXX_HPP_INCLUDED |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 4 | |
| 5 | // Copyright Aleksey Gurtovoy 2002-2006 |
| 6 | // Copyright David Abrahams 2002-2003 |
| 7 | // Copyright Daniel Walker 2007 |
| 8 | // |
| 9 | // Distributed under the Boost Software License, Version 1.0. |
| 10 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 11 | // http://www.boost.org/LICENSE_1_0.txt) |
| 12 | // |
| 13 | // See http://www.boost.org/libs/mpl for documentation. |
| 14 | |
| 15 | // $Id: has_xxx.hpp 64146 2010-07-19 00:46:31Z djwalker $ |
| 16 | // $Date: 2010-07-18 17:46:31 -0700 (Sun, 18 Jul 2010) $ |
| 17 | // $Revision: 64146 $ |
| 18 | |
| 19 | #include <ndnboost/mpl/bool.hpp> |
| 20 | #include <ndnboost/mpl/aux_/na_spec.hpp> |
| 21 | #include <ndnboost/mpl/aux_/type_wrapper.hpp> |
| 22 | #include <ndnboost/mpl/aux_/yes_no.hpp> |
| 23 | #include <ndnboost/mpl/aux_/config/gcc.hpp> |
| 24 | #include <ndnboost/mpl/aux_/config/has_xxx.hpp> |
| 25 | #include <ndnboost/mpl/aux_/config/msvc_typename.hpp> |
| 26 | #include <ndnboost/mpl/aux_/config/msvc.hpp> |
| 27 | #include <ndnboost/mpl/aux_/config/static_constant.hpp> |
| 28 | #include <ndnboost/mpl/aux_/config/workaround.hpp> |
| 29 | |
| 30 | #include <ndnboost/preprocessor/array/elem.hpp> |
| 31 | #include <ndnboost/preprocessor/cat.hpp> |
| 32 | #include <ndnboost/preprocessor/control/if.hpp> |
| 33 | #include <ndnboost/preprocessor/repetition/enum_params.hpp> |
| 34 | #include <ndnboost/preprocessor/repetition/enum_trailing_params.hpp> |
| 35 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 36 | #if NDNBOOST_WORKAROUND( __BORLANDC__, NDNBOOST_TESTED_AT(0x590) ) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 37 | # include <ndnboost/type_traits/is_class.hpp> |
| 38 | #endif |
| 39 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 40 | #if !defined(NDNBOOST_MPL_CFG_NO_HAS_XXX) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 42 | # if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1300) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 43 | |
| 44 | // agurt, 11/sep/02: MSVC-specific version (< 7.1), based on a USENET |
| 45 | // newsgroup's posting by John Madsen (comp.lang.c++.moderated, |
| 46 | // 1999-11-12 19:17:06 GMT); the code is _not_ standard-conforming, but |
| 47 | // it works way more reliably than the SFINAE-based implementation |
| 48 | |
| 49 | // Modified dwa 8/Oct/02 to handle reference types. |
| 50 | |
| 51 | # include <ndnboost/mpl/if.hpp> |
| 52 | # include <ndnboost/mpl/bool.hpp> |
| 53 | |
| 54 | namespace ndnboost { namespace mpl { namespace aux { |
| 55 | |
| 56 | struct has_xxx_tag; |
| 57 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 58 | #if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, == 1300) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 59 | template< typename U > struct msvc_incomplete_array |
| 60 | { |
| 61 | typedef char (&type)[sizeof(U) + 1]; |
| 62 | }; |
| 63 | #endif |
| 64 | |
| 65 | template< typename T > |
| 66 | struct msvc_is_incomplete |
| 67 | { |
| 68 | // MSVC is capable of some kinds of SFINAE. If U is an incomplete |
| 69 | // type, it won't pick the second overload |
| 70 | static char tester(...); |
| 71 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 72 | #if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, == 1300) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 73 | template< typename U > |
| 74 | static typename msvc_incomplete_array<U>::type tester(type_wrapper<U>); |
| 75 | #else |
| 76 | template< typename U > |
| 77 | static char (& tester(type_wrapper<U>) )[sizeof(U)+1]; |
| 78 | #endif |
| 79 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 80 | NDNBOOST_STATIC_CONSTANT(bool, value = |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 81 | sizeof(tester(type_wrapper<T>())) == 1 |
| 82 | ); |
| 83 | }; |
| 84 | |
| 85 | template<> |
| 86 | struct msvc_is_incomplete<int> |
| 87 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 88 | NDNBOOST_STATIC_CONSTANT(bool, value = false); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | }}} |
| 92 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 94 | template< typename T, typename name = ::ndnboost::mpl::aux::has_xxx_tag > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 95 | struct NDNBOOST_PP_CAT(trait,_impl) : T \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 96 | { \ |
| 97 | static ndnboost::mpl::aux::no_tag \ |
| 98 | test(void(*)(::ndnboost::mpl::aux::has_xxx_tag)); \ |
| 99 | \ |
| 100 | static ndnboost::mpl::aux::yes_tag test(...); \ |
| 101 | \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 102 | NDNBOOST_STATIC_CONSTANT(bool, value = \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 103 | sizeof(test(static_cast<void(*)(name)>(0))) \ |
| 104 | != sizeof(ndnboost::mpl::aux::no_tag) \ |
| 105 | ); \ |
| 106 | typedef ndnboost::mpl::bool_<value> type; \ |
| 107 | }; \ |
| 108 | \ |
| 109 | template< typename T, typename fallback_ = ndnboost::mpl::bool_<default_> > \ |
| 110 | struct trait \ |
| 111 | : ndnboost::mpl::if_c< \ |
| 112 | ndnboost::mpl::aux::msvc_is_incomplete<T>::value \ |
| 113 | , ndnboost::mpl::bool_<false> \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 114 | , NDNBOOST_PP_CAT(trait,_impl)<T> \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 115 | >::type \ |
| 116 | { \ |
| 117 | }; \ |
| 118 | \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 119 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, void) \ |
| 120 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, bool) \ |
| 121 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, char) \ |
| 122 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed char) \ |
| 123 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned char) \ |
| 124 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed short) \ |
| 125 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned short) \ |
| 126 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed int) \ |
| 127 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned int) \ |
| 128 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed long) \ |
| 129 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned long) \ |
| 130 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, float) \ |
| 131 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, double) \ |
| 132 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, long double) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 133 | /**/ |
| 134 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 135 | # define NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, T) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 136 | template<> struct trait<T> \ |
| 137 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 138 | NDNBOOST_STATIC_CONSTANT(bool, value = false); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 139 | typedef ndnboost::mpl::bool_<false> type; \ |
| 140 | }; \ |
| 141 | /**/ |
| 142 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 143 | #if !defined(NDNBOOST_NO_INTRINSIC_WCHAR_T) |
| 144 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \ |
| 145 | NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \ |
| 146 | NDNBOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, wchar_t) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 147 | /**/ |
| 148 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 149 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \ |
| 150 | NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 151 | /**/ |
| 152 | #endif |
| 153 | |
| 154 | |
| 155 | // SFINAE-based implementations below are derived from a USENET newsgroup's |
| 156 | // posting by Rani Sharoni (comp.lang.c++.moderated, 2002-03-17 07:45:09 PST) |
| 157 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 158 | # elif NDNBOOST_WORKAROUND(NDNBOOST_MSVC, NDNBOOST_TESTED_AT(1400)) \ |
| 159 | || NDNBOOST_WORKAROUND(__IBMCPP__, <= 700) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 160 | |
| 161 | // MSVC 7.1+ & VACPP |
| 162 | |
| 163 | // agurt, 15/jun/05: replace overload-based SFINAE implementation with SFINAE |
| 164 | // applied to partial specialization to fix some apparently random failures |
| 165 | // (thanks to Daniel Wallin for researching this!) |
| 166 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 167 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 168 | template< typename T > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 169 | struct NDNBOOST_PP_CAT(trait, _msvc_sfinae_helper) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 170 | { \ |
| 171 | typedef void type; \ |
| 172 | };\ |
| 173 | \ |
| 174 | template< typename T, typename U = void > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 175 | struct NDNBOOST_PP_CAT(trait,_impl_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 176 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 177 | NDNBOOST_STATIC_CONSTANT(bool, value = false); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 178 | typedef ndnboost::mpl::bool_<value> type; \ |
| 179 | }; \ |
| 180 | \ |
| 181 | template< typename T > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 182 | struct NDNBOOST_PP_CAT(trait,_impl_)< \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 183 | T \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 184 | , typename NDNBOOST_PP_CAT(trait, _msvc_sfinae_helper)< typename T::name >::type \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 185 | > \ |
| 186 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 187 | NDNBOOST_STATIC_CONSTANT(bool, value = true); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 188 | typedef ndnboost::mpl::bool_<value> type; \ |
| 189 | }; \ |
| 190 | \ |
| 191 | template< typename T, typename fallback_ = ndnboost::mpl::bool_<default_> > \ |
| 192 | struct trait \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 193 | : NDNBOOST_PP_CAT(trait,_impl_)<T> \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 194 | { \ |
| 195 | }; \ |
| 196 | /**/ |
| 197 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 198 | # elif NDNBOOST_WORKAROUND( __BORLANDC__, NDNBOOST_TESTED_AT(0x590) ) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 199 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 200 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_BCB_DEF(trait, trait_tester, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 201 | template< typename T, bool IS_CLASS > \ |
| 202 | struct trait_tester \ |
| 203 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 204 | NDNBOOST_STATIC_CONSTANT( bool, value = false ); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 205 | }; \ |
| 206 | template< typename T > \ |
| 207 | struct trait_tester< T, true > \ |
| 208 | { \ |
| 209 | struct trait_tester_impl \ |
| 210 | { \ |
| 211 | template < class U > \ |
| 212 | static int resolve( ndnboost::mpl::aux::type_wrapper<U> const volatile * \ |
| 213 | , ndnboost::mpl::aux::type_wrapper<typename U::name >* = 0 ); \ |
| 214 | static char resolve( ... ); \ |
| 215 | }; \ |
| 216 | typedef ndnboost::mpl::aux::type_wrapper<T> t_; \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 217 | NDNBOOST_STATIC_CONSTANT( bool, value = ( sizeof( trait_tester_impl::resolve( static_cast< t_ * >(0) ) ) == sizeof(int) ) ); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 218 | }; \ |
| 219 | template< typename T, typename fallback_ = ndnboost::mpl::bool_<default_> > \ |
| 220 | struct trait \ |
| 221 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 222 | NDNBOOST_STATIC_CONSTANT( bool, value = (trait_tester< T, ndnboost::is_class< T >::value >::value) ); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 223 | typedef ndnboost::mpl::bool_< trait< T, fallback_ >::value > type; \ |
| 224 | }; |
| 225 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 226 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \ |
| 227 | NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_BCB_DEF( trait \ |
| 228 | , NDNBOOST_PP_CAT(trait,_tester) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 229 | , name \ |
| 230 | , default_ ) \ |
| 231 | /**/ |
| 232 | |
| 233 | # else // other SFINAE-capable compilers |
| 234 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 235 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 236 | template< typename T, typename fallback_ = ndnboost::mpl::bool_<default_> > \ |
| 237 | struct trait \ |
| 238 | { \ |
| 239 | struct gcc_3_2_wknd \ |
| 240 | { \ |
| 241 | template< typename U > \ |
| 242 | static ndnboost::mpl::aux::yes_tag test( \ |
| 243 | ndnboost::mpl::aux::type_wrapper<U> const volatile* \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 244 | , ndnboost::mpl::aux::type_wrapper<NDNBOOST_MSVC_TYPENAME U::name>* = 0 \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 245 | ); \ |
| 246 | \ |
| 247 | static ndnboost::mpl::aux::no_tag test(...); \ |
| 248 | }; \ |
| 249 | \ |
| 250 | typedef ndnboost::mpl::aux::type_wrapper<T> t_; \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 251 | NDNBOOST_STATIC_CONSTANT(bool, value = \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 252 | sizeof(gcc_3_2_wknd::test(static_cast<t_*>(0))) \ |
| 253 | == sizeof(ndnboost::mpl::aux::yes_tag) \ |
| 254 | ); \ |
| 255 | typedef ndnboost::mpl::bool_<value> type; \ |
| 256 | }; \ |
| 257 | /**/ |
| 258 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 259 | # endif // NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1300) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 260 | |
| 261 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 262 | #else // NDNBOOST_MPL_CFG_NO_HAS_XXX |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 263 | |
| 264 | // placeholder implementation |
| 265 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 266 | # define NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 267 | template< typename T, typename fallback_ = ndnboost::mpl::bool_<default_> > \ |
| 268 | struct trait \ |
| 269 | { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 270 | NDNBOOST_STATIC_CONSTANT(bool, value = fallback_::value); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 271 | typedef fallback_ type; \ |
| 272 | }; \ |
| 273 | /**/ |
| 274 | |
| 275 | #endif |
| 276 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 277 | #define NDNBOOST_MPL_HAS_XXX_TRAIT_DEF(name) \ |
| 278 | NDNBOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(NDNBOOST_PP_CAT(has_,name), name, false) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 279 | /**/ |
| 280 | |
| 281 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 282 | #if !defined(NDNBOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 283 | |
| 284 | // Create a boolean Metafunction to detect a nested template |
| 285 | // member. This implementation is based on a USENET newsgroup's |
| 286 | // posting by Aleksey Gurtovoy (comp.lang.c++.moderated, 2002-03-19), |
| 287 | // Rani Sharoni's USENET posting cited above, the non-template has_xxx |
| 288 | // implementations above, and discussion on the Boost mailing list. |
| 289 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 290 | # if !defined(NDNBOOST_MPL_HAS_XXX_NO_WRAPPED_TYPES) |
| 291 | # if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1400) |
| 292 | # define NDNBOOST_MPL_HAS_XXX_NO_WRAPPED_TYPES 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 293 | # endif |
| 294 | # endif |
| 295 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 296 | # if !defined(NDNBOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION) |
| 297 | # if (defined(NDNBOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)) |
| 298 | # define NDNBOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 299 | # endif |
| 300 | # endif |
| 301 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 302 | # if !defined(NDNBOOST_MPL_HAS_XXX_NEEDS_TEMPLATE_SFINAE) |
| 303 | # if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1400) |
| 304 | # define NDNBOOST_MPL_HAS_XXX_NEEDS_TEMPLATE_SFINAE 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 305 | # endif |
| 306 | # endif |
| 307 | |
| 308 | // NOTE: Many internal implementation macros take a Boost.Preprocessor |
| 309 | // array argument called args which is of the following form. |
| 310 | // ( 4, ( trait, name, max_arity, default_ ) ) |
| 311 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 312 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_NAME(args) \ |
| 313 | NDNBOOST_PP_CAT(NDNBOOST_PP_ARRAY_ELEM(0, args) , _introspect) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 314 | /**/ |
| 315 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 316 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME(args, n) \ |
| 317 | NDNBOOST_PP_CAT(NDNBOOST_PP_CAT(NDNBOOST_PP_ARRAY_ELEM(0, args) , _substitute), n) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 318 | /**/ |
| 319 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 320 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args) \ |
| 321 | NDNBOOST_PP_CAT(NDNBOOST_PP_ARRAY_ELEM(0, args) , _test) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 322 | /**/ |
| 323 | |
| 324 | // Thanks to Guillaume Melquiond for pointing out the need for the |
| 325 | // "substitute" template as an argument to the overloaded test |
| 326 | // functions to get SFINAE to work for member templates with the |
| 327 | // correct name but different number of arguments. |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 328 | # define NDNBOOST_MPL_HAS_MEMBER_MULTI_SUBSTITUTE(z, n, args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 329 | template< \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 330 | template< NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_INC(n), typename V) > class V \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 331 | > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 332 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME(args, n) { \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 333 | }; \ |
| 334 | /**/ |
| 335 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 336 | # define NDNBOOST_MPL_HAS_MEMBER_SUBSTITUTE(args, substitute_macro) \ |
| 337 | NDNBOOST_PP_REPEAT( \ |
| 338 | NDNBOOST_PP_ARRAY_ELEM(2, args) \ |
| 339 | , NDNBOOST_MPL_HAS_MEMBER_MULTI_SUBSTITUTE \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 340 | , args \ |
| 341 | ) \ |
| 342 | /**/ |
| 343 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 344 | # if !NDNBOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION |
| 345 | # define NDNBOOST_MPL_HAS_MEMBER_REJECT(args, member_macro) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 346 | template< typename V > \ |
| 347 | static ndnboost::mpl::aux::no_tag \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 348 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)(...); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 349 | /**/ |
| 350 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 351 | # define NDNBOOST_MPL_HAS_MEMBER_REJECT(args, member_macro) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 352 | static ndnboost::mpl::aux::no_tag \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 353 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)(...); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 354 | /**/ |
| 355 | # endif |
| 356 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 357 | # if !NDNBOOST_MPL_HAS_XXX_NO_WRAPPED_TYPES |
| 358 | # define NDNBOOST_MPL_HAS_MEMBER_MULTI_ACCEPT(z, n, args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 359 | template< typename V > \ |
| 360 | static ndnboost::mpl::aux::yes_tag \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 361 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 362 | ndnboost::mpl::aux::type_wrapper< V > const volatile* \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 363 | , NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME(args, n) < \ |
| 364 | V::template NDNBOOST_PP_ARRAY_ELEM(1, args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 365 | >* = 0 \ |
| 366 | ); \ |
| 367 | /**/ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 368 | # define NDNBOOST_MPL_HAS_MEMBER_ACCEPT(args, member_macro) \ |
| 369 | NDNBOOST_PP_REPEAT( \ |
| 370 | NDNBOOST_PP_ARRAY_ELEM(2, args) \ |
| 371 | , NDNBOOST_MPL_HAS_MEMBER_MULTI_ACCEPT \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 372 | , args \ |
| 373 | ) \ |
| 374 | /**/ |
| 375 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 376 | # define NDNBOOST_MPL_HAS_MEMBER_ACCEPT(args, member_macro) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 377 | template< typename V > \ |
| 378 | static ndnboost::mpl::aux::yes_tag \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 379 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 380 | V const volatile* \ |
| 381 | , member_macro(args, V, T)* = 0 \ |
| 382 | ); \ |
| 383 | /**/ |
| 384 | # endif |
| 385 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 386 | # if !NDNBOOST_MPL_HAS_XXX_NO_EXPLICIT_TEST_FUNCTION |
| 387 | # define NDNBOOST_MPL_HAS_MEMBER_TEST(args) \ |
| 388 | sizeof(NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)< U >(0)) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 389 | == sizeof(ndnboost::mpl::aux::yes_tag) \ |
| 390 | /**/ |
| 391 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 392 | # if !NDNBOOST_MPL_HAS_XXX_NO_WRAPPED_TYPES |
| 393 | # define NDNBOOST_MPL_HAS_MEMBER_TEST(args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 394 | sizeof( \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 395 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 396 | static_cast< ndnboost::mpl::aux::type_wrapper< U >* >(0) \ |
| 397 | ) \ |
| 398 | ) == sizeof(ndnboost::mpl::aux::yes_tag) \ |
| 399 | /**/ |
| 400 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 401 | # define NDNBOOST_MPL_HAS_MEMBER_TEST(args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 402 | sizeof( \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 403 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 404 | static_cast< U* >(0) \ |
| 405 | ) \ |
| 406 | ) == sizeof(ndnboost::mpl::aux::yes_tag) \ |
| 407 | /**/ |
| 408 | # endif |
| 409 | # endif |
| 410 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 411 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECT( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 412 | args, substitute_macro, member_macro \ |
| 413 | ) \ |
| 414 | template< typename U > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 415 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_NAME(args) { \ |
| 416 | NDNBOOST_MPL_HAS_MEMBER_SUBSTITUTE(args, substitute_macro) \ |
| 417 | NDNBOOST_MPL_HAS_MEMBER_REJECT(args, member_macro) \ |
| 418 | NDNBOOST_MPL_HAS_MEMBER_ACCEPT(args, member_macro) \ |
| 419 | NDNBOOST_STATIC_CONSTANT( \ |
| 420 | bool, value = NDNBOOST_MPL_HAS_MEMBER_TEST(args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 421 | ); \ |
| 422 | typedef ndnboost::mpl::bool_< value > type; \ |
| 423 | }; \ |
| 424 | /**/ |
| 425 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 426 | # define NDNBOOST_MPL_HAS_MEMBER_IMPLEMENTATION( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 427 | args, introspect_macro, substitute_macro, member_macro \ |
| 428 | ) \ |
| 429 | template< \ |
| 430 | typename T \ |
| 431 | , typename fallback_ \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 432 | = ndnboost::mpl::bool_< NDNBOOST_PP_ARRAY_ELEM(3, args) > \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 433 | > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 434 | class NDNBOOST_PP_ARRAY_ELEM(0, args) { \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 435 | introspect_macro(args, substitute_macro, member_macro) \ |
| 436 | public: \ |
| 437 | static const bool value \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 438 | = NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_NAME(args)< T >::value; \ |
| 439 | typedef typename NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_NAME(args)< \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 440 | T \ |
| 441 | >::type type; \ |
| 442 | }; \ |
| 443 | /**/ |
| 444 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 445 | // NDNBOOST_MPL_HAS_MEMBER_WITH_FUNCTION_SFINAE expands to the full |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 446 | // implementation of the function-based metafunction. Compile with -E |
| 447 | // to see the preprocessor output for this macro. |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 448 | # define NDNBOOST_MPL_HAS_MEMBER_WITH_FUNCTION_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 449 | args, substitute_macro, member_macro \ |
| 450 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 451 | NDNBOOST_MPL_HAS_MEMBER_IMPLEMENTATION( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 452 | args \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 453 | , NDNBOOST_MPL_HAS_MEMBER_INTROSPECT \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 454 | , substitute_macro \ |
| 455 | , member_macro \ |
| 456 | ) \ |
| 457 | /**/ |
| 458 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 459 | # if NDNBOOST_MPL_HAS_XXX_NEEDS_TEMPLATE_SFINAE |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 460 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 461 | # if !defined(NDNBOOST_MPL_HAS_XXX_NEEDS_NAMESPACE_LEVEL_SUBSTITUTE) |
| 462 | # if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1400) |
| 463 | # define NDNBOOST_MPL_HAS_XXX_NEEDS_NAMESPACE_LEVEL_SUBSTITUTE 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 464 | # endif |
| 465 | # endif |
| 466 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 467 | # if !NDNBOOST_MPL_HAS_XXX_NEEDS_NAMESPACE_LEVEL_SUBSTITUTE |
| 468 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 469 | args, n \ |
| 470 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 471 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME(args, n) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 472 | /**/ |
| 473 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 474 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 475 | args, n \ |
| 476 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 477 | NDNBOOST_PP_CAT( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 478 | boost_mpl_has_xxx_ \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 479 | , NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME(args, n) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 480 | ) \ |
| 481 | /**/ |
| 482 | # endif |
| 483 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 484 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_TAG_NAME( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 485 | args \ |
| 486 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 487 | NDNBOOST_PP_CAT( \ |
| 488 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 489 | args, 0 \ |
| 490 | ) \ |
| 491 | , _tag \ |
| 492 | ) \ |
| 493 | /**/ |
| 494 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 495 | # define NDNBOOST_MPL_HAS_MEMBER_MULTI_SUBSTITUTE_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 496 | z, n, args \ |
| 497 | ) \ |
| 498 | template< \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 499 | template< NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_INC(n), typename U) > class U \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 500 | > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 501 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 502 | args, n \ |
| 503 | ) { \ |
| 504 | typedef \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 505 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_TAG_NAME(args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 506 | type; \ |
| 507 | }; \ |
| 508 | /**/ |
| 509 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 510 | # define NDNBOOST_MPL_HAS_MEMBER_SUBSTITUTE_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 511 | args, substitute_macro \ |
| 512 | ) \ |
| 513 | typedef void \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 514 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_TAG_NAME(args); \ |
| 515 | NDNBOOST_PP_REPEAT( \ |
| 516 | NDNBOOST_PP_ARRAY_ELEM(2, args) \ |
| 517 | , NDNBOOST_MPL_HAS_MEMBER_MULTI_SUBSTITUTE_WITH_TEMPLATE_SFINAE \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 518 | , args \ |
| 519 | ) \ |
| 520 | /**/ |
| 521 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 522 | # define NDNBOOST_MPL_HAS_MEMBER_REJECT_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 523 | args, member_macro \ |
| 524 | ) \ |
| 525 | template< \ |
| 526 | typename U \ |
| 527 | , typename V \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 528 | = NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_TAG_NAME(args) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 529 | > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 530 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args) { \ |
| 531 | NDNBOOST_STATIC_CONSTANT(bool, value = false); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 532 | typedef ndnboost::mpl::bool_< value > type; \ |
| 533 | }; \ |
| 534 | /**/ |
| 535 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 536 | # define NDNBOOST_MPL_HAS_MEMBER_MULTI_ACCEPT_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 537 | z, n, args \ |
| 538 | ) \ |
| 539 | template< typename U > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 540 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)< \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 541 | U \ |
| 542 | , typename \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 543 | NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_SUBSTITUTE_NAME_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 544 | args, n \ |
| 545 | )< \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 546 | NDNBOOST_MSVC_TYPENAME U::NDNBOOST_PP_ARRAY_ELEM(1, args)< > \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 547 | >::type \ |
| 548 | > { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 549 | NDNBOOST_STATIC_CONSTANT(bool, value = true); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 550 | typedef ndnboost::mpl::bool_< value > type; \ |
| 551 | }; \ |
| 552 | /**/ |
| 553 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 554 | # define NDNBOOST_MPL_HAS_MEMBER_ACCEPT_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 555 | args, member_macro \ |
| 556 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 557 | NDNBOOST_PP_REPEAT( \ |
| 558 | NDNBOOST_PP_ARRAY_ELEM(2, args) \ |
| 559 | , NDNBOOST_MPL_HAS_MEMBER_MULTI_ACCEPT_WITH_TEMPLATE_SFINAE \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 560 | , args \ |
| 561 | ) \ |
| 562 | /**/ |
| 563 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 564 | # define NDNBOOST_MPL_HAS_MEMBER_INTROSPECT_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 565 | args, substitute_macro, member_macro \ |
| 566 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 567 | NDNBOOST_MPL_HAS_MEMBER_REJECT_WITH_TEMPLATE_SFINAE(args, member_macro) \ |
| 568 | NDNBOOST_MPL_HAS_MEMBER_ACCEPT_WITH_TEMPLATE_SFINAE(args, member_macro) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 569 | template< typename U > \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 570 | struct NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_NAME(args) \ |
| 571 | : NDNBOOST_MPL_HAS_MEMBER_INTROSPECTION_TEST_NAME(args)< U > { \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 572 | }; \ |
| 573 | /**/ |
| 574 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 575 | // NDNBOOST_MPL_HAS_MEMBER_WITH_TEMPLATE_SFINAE expands to the full |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 576 | // implementation of the template-based metafunction. Compile with -E |
| 577 | // to see the preprocessor output for this macro. |
| 578 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 579 | // Note that if NDNBOOST_MPL_HAS_XXX_NEEDS_NAMESPACE_LEVEL_SUBSTITUTE is |
| 580 | // defined NDNBOOST_MPL_HAS_MEMBER_SUBSTITUTE_WITH_TEMPLATE_SFINAE needs |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 581 | // to be expanded at namespace level before |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 582 | // NDNBOOST_MPL_HAS_MEMBER_WITH_TEMPLATE_SFINAE can be used. |
| 583 | # define NDNBOOST_MPL_HAS_MEMBER_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 584 | args, substitute_macro, member_macro \ |
| 585 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 586 | NDNBOOST_MPL_HAS_MEMBER_SUBSTITUTE_WITH_TEMPLATE_SFINAE( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 587 | args, substitute_macro \ |
| 588 | ) \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 589 | NDNBOOST_MPL_HAS_MEMBER_IMPLEMENTATION( \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 590 | args \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 591 | , NDNBOOST_MPL_HAS_MEMBER_INTROSPECT_WITH_TEMPLATE_SFINAE \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 592 | , substitute_macro \ |
| 593 | , member_macro \ |
| 594 | ) \ |
| 595 | /**/ |
| 596 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 597 | # endif // NDNBOOST_MPL_HAS_XXX_NEEDS_TEMPLATE_SFINAE |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 598 | |
| 599 | // Note: In the current implementation the parameter and access macros |
| 600 | // are no longer expanded. |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 601 | # if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1400) |
| 602 | # define NDNBOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(trait, name, default_) \ |
| 603 | NDNBOOST_MPL_HAS_MEMBER_WITH_FUNCTION_SFINAE( \ |
| 604 | ( 4, ( trait, name, NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY, default_ ) ) \ |
| 605 | , NDNBOOST_MPL_HAS_MEMBER_TEMPLATE_SUBSTITUTE_PARAMETER \ |
| 606 | , NDNBOOST_MPL_HAS_MEMBER_TEMPLATE_ACCESS \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 607 | ) \ |
| 608 | /**/ |
| 609 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 610 | # define NDNBOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(trait, name, default_) \ |
| 611 | NDNBOOST_MPL_HAS_MEMBER_WITH_TEMPLATE_SFINAE( \ |
| 612 | ( 4, ( trait, name, NDNBOOST_MPL_LIMIT_METAFUNCTION_ARITY, default_ ) ) \ |
| 613 | , NDNBOOST_MPL_HAS_MEMBER_TEMPLATE_SUBSTITUTE_PARAMETER \ |
| 614 | , NDNBOOST_MPL_HAS_MEMBER_TEMPLATE_ACCESS \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 615 | ) \ |
| 616 | /**/ |
| 617 | # endif |
| 618 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 619 | #else // NDNBOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 620 | |
| 621 | // placeholder implementation |
| 622 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 623 | # define NDNBOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(trait, name, default_) \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 624 | template< typename T \ |
| 625 | , typename fallback_ = ndnboost::mpl::bool_< default_ > > \ |
| 626 | struct trait { \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 627 | NDNBOOST_STATIC_CONSTANT(bool, value = fallback_::value); \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 628 | typedef fallback_ type; \ |
| 629 | }; \ |
| 630 | /**/ |
| 631 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 632 | #endif // NDNBOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 633 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 634 | # define NDNBOOST_MPL_HAS_XXX_TEMPLATE_DEF(name) \ |
| 635 | NDNBOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF( \ |
| 636 | NDNBOOST_PP_CAT(has_, name), name, false \ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 637 | ) \ |
| 638 | /**/ |
| 639 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 640 | #endif // NDNBOOST_MPL_HAS_XXX_HPP_INCLUDED |