From 7f5caca12eac63ce3381493f3f8a861c35b03076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 7 Sep 2017 20:17:05 +0200 Subject: [PATCH] Extract BOOST_INTRUSIVE_HAS_TYPE trait --- include/boost/intrusive/detail/mpl.hpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/boost/intrusive/detail/mpl.hpp b/include/boost/intrusive/detail/mpl.hpp index 8d227a1..1523088 100644 --- a/include/boost/intrusive/detail/mpl.hpp +++ b/include/boost/intrusive/detail/mpl.hpp @@ -86,8 +86,8 @@ struct ls_zeros<1> // Infrastructure for providing a default type for T::TNAME if absent. #define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \ - template \ - struct boost_intrusive_default_type_ ## TNAME \ + template \ + struct boost_intrusive_has_type_ ## TNAME \ { \ template \ static char test(int, typename X::TNAME*); \ @@ -95,13 +95,18 @@ struct ls_zeros<1> template \ static int test(...); \ \ - struct DefaultWrap { typedef DefaultType TNAME; }; \ - \ static const bool value = (1 == sizeof(test(0, 0))); \ + }; \ + \ + template \ + struct boost_intrusive_default_type_ ## TNAME \ + { \ + struct DefaultWrap { typedef DefaultType TNAME; }; \ \ typedef typename \ ::boost::intrusive::detail::if_c \ - ::type::TNAME type; \ + < boost_intrusive_has_type_ ## TNAME::value \ + , T, DefaultWrap>::type::TNAME type; \ }; \ // @@ -110,6 +115,11 @@ struct ls_zeros<1> boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \ // +#define BOOST_INTRUSIVE_HAS_TYPE(INSTANTIATION_NS_PREFIX, T, TNAME) \ + INSTANTIATION_NS_PREFIX \ + boost_intrusive_has_type_ ## TNAME< T >::value \ +// + #define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\ template \ struct boost_intrusive_eval_default_type_ ## TNAME \