Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64796 - sandbox/chrono/boost/type_traits
From: vicente.botet_at_[hidden]
Date: 2010-08-14 09:48:26


Author: viboes
Date: 2010-08-14 09:48:24 EDT (Sat, 14 Aug 2010)
New Revision: 64796
URL: http://svn.boost.org/trac/boost/changeset/64796

Log:
Avoid the use of typeof on common_type.hpp
Text files modified:
   sandbox/chrono/boost/type_traits/common_type.hpp | 78 +++++++++++++++++++++++++++------------
   1 files changed, 53 insertions(+), 25 deletions(-)

Modified: sandbox/chrono/boost/type_traits/common_type.hpp
==============================================================================
--- sandbox/chrono/boost/type_traits/common_type.hpp (original)
+++ sandbox/chrono/boost/type_traits/common_type.hpp 2010-08-14 09:48:24 EDT (Sat, 14 Aug 2010)
@@ -37,7 +37,7 @@
 #elif defined(BOOST_COMMON_TYPE_USES_ARRAY_ASSERT)
 #define BOOST_COMMON_TYPE_CONCAT(A,B) A##B
 #define BOOST_COMMON_TYPE_NAME(A,B) BOOST_COMMON_TYPE_CONCAT(A,B)
-#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_COMMON_TYPE_NAME(boost_common_type_test_,__LINE__)[CND];
+#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_COMMON_TYPE_NAME(__boost_common_type_test_,__LINE__)[CND];
 #else
 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES)
 #endif
@@ -46,6 +46,8 @@
 #define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type"
 #endif
 
+#include <boost/mpl/if.hpp>
+
 //----------------------------------------------------------------------------//
 // //
 // C++03 implementation of //
@@ -57,64 +59,90 @@
 
 namespace boost {
 
-// prototype
+// prototype
 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
     template<typename... T>
     struct common_type;
 #else // or no specialization
     template <class T, class U = void, class V = void>
- struct common_type
+ struct common_type
     {
     public:
         typedef typename common_type<typename common_type<T, U>::type, V>::type type;
     };
-#endif
+#endif
 
 
 // 1 arg
     template<typename T>
 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
- struct common_type<T>
+ struct common_type<T>
 #else
     struct common_type<T, void, void>
 
-#endif
+#endif
     {
- BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, "must be complete type",(T));
+ BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
     public:
         typedef T type;
     };
 
 // 2 args
-
-#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
- template <class T, class U>
- struct common_type<T, U>
-#else
+
+
+ namespace detail {
     template <class T, class U>
- struct common_type<T, U, void>
-#endif
+ struct common_type_2
     {
- BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, "must be complete type",(T));
- BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, "must be complete type",(T));
+ private:
+ BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
+ BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U));
         static bool m_f(); // workaround gcc bug; not required by std
 #if !defined(BOOST_NO_RVALUE_REFERENCES) \
     && !defined(BOOST_NO_DECLTYPE)
             static T&& m_t();
             static U&& m_u();
 
- public:
- typedef decltype(m_f() ? m_t() : m_u()) type;
+ public:
+ typedef decltype(m_f() ? m_t() : m_u()) type;
+#else
+ static T m_t();
+ static U m_u();
+#if 0
+ public:
+ typedef BOOST_TYPEOF_TPL(m_f() ? m_t() : m_u()) type;
 #else
- static T m_t();
- static U m_u();
- public:
- typedef BOOST_TYPEOF_TPL(m_f() ? m_t() : m_u()) type;
-#endif
+ typedef char (&yes)[1];
+ typedef char (&no)[2];
+ static yes deduce(T);
+ static no deduce(U);
+ public:
+ typedef typename mpl::if_c< sizeof( deduce(m_f() ? m_t() : m_u()) ) == sizeof( yes ), T, U >::type type;
+
+#endif
+#endif
+ };
+
+ template <class T>
+ struct common_type_2<T, T>
+ {
+ typedef T type;
     };
-
+ }
+
+#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
+ template <class T, class U>
+ struct common_type<T, U>
+#else
+ template <class T, class U>
+ struct common_type<T, U, void>
+#endif
+ : detail::common_type_2<T,U>
+ { };
+
+
 // 3 or more args
-#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
+#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
     template<typename T, typename U, typename... V>
     struct common_type<T, U, V...> {
     public:


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