From 264017e2a9bdbfcc24517ce05f8ef96df0a8c45b Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 16 Jun 2014 00:00:09 -0700 Subject: [PATCH] more robust implementation for BOOST_RANGE_EXTRACT_OPTIONAL_TYPE --- .../range/detail/extract_optional_type.hpp | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/include/boost/range/detail/extract_optional_type.hpp b/include/boost/range/detail/extract_optional_type.hpp index aa4dd80..0381434 100644 --- a/include/boost/range/detail/extract_optional_type.hpp +++ b/include/boost/range/detail/extract_optional_type.hpp @@ -15,36 +15,32 @@ #endif #include +#include +#include -#ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS - -#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ - template< typename C > \ - struct extract_ ## a_typedef \ - { \ - typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ - }; - -#else - -namespace boost { - namespace range_detail { - template< typename T > struct exists { typedef void type; }; - } -} +#if !defined(BOOST_MPL_CFG_NO_HAS_XXX) // Defines extract_some_typedef which exposes T::some_typedef as // extract_some_typedef::type if T::some_typedef exists. Otherwise // extract_some_typedef is empty. -#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ - template< typename C, typename Enable=void > \ - struct extract_ ## a_typedef \ - {}; \ - template< typename C > \ - struct extract_ ## a_typedef< C \ - , BOOST_DEDUCED_TYPENAME boost::range_detail::exists< BOOST_DEDUCED_TYPENAME C::a_typedef >::type \ - > { \ - typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ +#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ + BOOST_MPL_HAS_XXX_TRAIT_DEF(a_typedef) \ + template< typename C, bool B = BOOST_PP_CAT(has_, a_typedef)::value > \ + struct BOOST_PP_CAT(extract_, a_typedef) \ + {}; \ + template< typename C > \ + struct BOOST_PP_CAT(extract_, a_typedef)< C, true > \ + { \ + typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ + }; + +#else + +#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ + template< typename C > \ + struct BOOST_PP_CAT(extract_, a_typedef) \ + { \ + typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ }; #endif