Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74173 - trunk/boost/unordered/detail
From: dnljms_at_[hidden]
Date: 2011-08-30 18:02:28


Author: danieljames
Date: 2011-08-30 18:02:27 EDT (Tue, 30 Aug 2011)
New Revision: 74173
URL: http://svn.boost.org/trac/boost/changeset/74173

Log:
Unordered: Another attempt at member detection.

Another stab in the dark. Doing SFINAE in the return type appears to
work well, apart for Visual C++ 8.0. Will have to see how the test
results go for some compilers.
Text files modified:
   trunk/boost/unordered/detail/allocator_helpers.hpp | 42 +++++++++++++++++++++++++++------------
   1 files changed, 29 insertions(+), 13 deletions(-)

Modified: trunk/boost/unordered/detail/allocator_helpers.hpp
==============================================================================
--- trunk/boost/unordered/detail/allocator_helpers.hpp (original)
+++ trunk/boost/unordered/detail/allocator_helpers.hpp 2011-08-30 18:02:27 EDT (Tue, 30 Aug 2011)
@@ -97,31 +97,45 @@
     struct choice1 : choice2 { typedef char (&type)[1]; };
     choice1 choose();
 
-#if !defined(__IBMCPP__)
+#if defined(BOOST_MSVC) && BOOST_MSVC <= 1400
 
-#define BOOST_UNORDERED_MEMBER_CHECK(tname) BOOST_DEDUCED_TYPENAME X::tname*
+ #define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
+ template <typename Tp, typename Default> \
+ struct default_type_ ## tname { \
+ \
+ template <typename X> \
+ static choice1::type test(choice1, \
+ BOOST_DEDUCED_TYPENAME X::tname* = 0); \
+ \
+ template <typename X> \
+ static choice2::type test(choice2, void* = 0); \
+ \
+ struct DefaultWrap { typedef Default tname; }; \
+ \
+ enum { value = (1 == sizeof(test<Tp>(choose()))) }; \
+ \
+ typedef BOOST_DEDUCED_TYPENAME \
+ boost::detail::if_true<value>:: \
+ BOOST_NESTED_TEMPLATE then<Tp, DefaultWrap> \
+ ::type::tname type; \
+ }
 
 #else
 
- template <typename T> struct wrap { typedef void* type; };
-
-#define BOOST_UNORDERED_MEMBER_CHECK(tname) \
- BOOST_DEDUCED_TYPENAME wrap< \
- BOOST_DEDUCED_TYPENAME X::tname \
- >::type
-
-#endif
+ template <typename T, typename T2>
+ struct sfinae : T2 {};
 
     #define BOOST_UNORDERED_DEFAULT_TYPE_TMPLT(tname) \
         template <typename Tp, typename Default> \
         struct default_type_ ## tname { \
                                                                             \
             template <typename X> \
- static choice1::type test(choice1, \
- BOOST_UNORDERED_MEMBER_CHECK(tname) = 0); \
+ static BOOST_DEDUCED_TYPENAME sfinae< \
+ BOOST_DEDUCED_TYPENAME X::tname, choice1>::type \
+ test(choice1); \
                                                                             \
             template <typename X> \
- static choice2::type test(choice2, void* = 0); \
+ static choice2::type test(choice2); \
                                                                             \
             struct DefaultWrap { typedef Default tname; }; \
                                                                             \
@@ -133,6 +147,8 @@
                 ::type::tname type; \
         }
 
+#endif
+
     #define BOOST_UNORDERED_DEFAULT_TYPE(T,tname, arg) \
         BOOST_DEDUCED_TYPENAME default_type_ ## tname<T, arg>::type
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk