Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65254 - in sandbox/chrono/boost/type_traits/ext: . detail
From: vicente.botet_at_[hidden]
Date: 2010-09-04 10:52:42


Author: viboes
Date: 2010-09-04 10:52:38 EDT (Sat, 04 Sep 2010)
New Revision: 65254
URL: http://svn.boost.org/trac/boost/changeset/65254

Log:
Continue the library split with Boost.TypeTraits.Ext
Added:
   sandbox/chrono/boost/type_traits/ext/add_rvalue_reference.hpp (contents, props changed)
   sandbox/chrono/boost/type_traits/ext/declval.hpp (contents, props changed)
Text files modified:
   sandbox/chrono/boost/type_traits/ext/common_type.hpp | 66 ++++++---------------------------------
   sandbox/chrono/boost/type_traits/ext/detail/common_type.hpp | 24 ++------------
   2 files changed, 14 insertions(+), 76 deletions(-)

Added: sandbox/chrono/boost/type_traits/ext/add_rvalue_reference.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/type_traits/ext/add_rvalue_reference.hpp 2010-09-04 10:52:38 EDT (Sat, 04 Sep 2010)
@@ -0,0 +1,68 @@
+// common_type.hpp ---------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP
+#define BOOST_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP
+
+#include <boost/config.hpp>
+
+//----------------------------------------------------------------------------//
+
+#include <boost/type_traits/is_void.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/type_traits/is_pointer.hpp>
+
+//----------------------------------------------------------------------------//
+// //
+// C++03 implementation of //
+// 20.7.6.2 Reference modifications [meta.trans.ref] //
+// Written by Vicente J. Botet Escriba //
+// //
+// If T names an object or function type then the member typedef type
+// shall name T&&; otherwise, type shall name T. [ Note: This rule reflects
+// the semantics of reference collapsing. For example, when a type T names
+// a type T1&, the type add_rvalue_reference<T>::type is not an rvalue
+// reference. —end note ]
+//----------------------------------------------------------------------------//
+
+namespace boost {
+
+namespace type_traits_detail {
+
+ template <typename T,
+ bool = !is_reference<T>::value
+ && ! is_pointer<T>::value
+ && !is_void<T>::value>
+ struct add_rvalue_reference_helper
+ { typedef T type; };
+
+ template <typename T>
+ struct add_rvalue_reference_helper<T, true>
+ {
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
+ typedef T&& type;
+#else
+ typedef T type;
+#endif
+ };
+}
+ /// add_rvalue_reference
+ template <typename T>
+ struct add_rvalue_reference
+ : public type_traits_detail::add_rvalue_reference_helper<T>
+ { };
+
+ template <typename T>
+ struct add_rvalue_reference<T&>
+ {
+ typedef T& type;
+ };
+
+
+} // namespace boost
+
+#endif // BOOST_TYPE_TRAITS_EXT_ADD_RVALUE_REFERENCE__HPP

Modified: sandbox/chrono/boost/type_traits/ext/common_type.hpp
==============================================================================
--- sandbox/chrono/boost/type_traits/ext/common_type.hpp (original)
+++ sandbox/chrono/boost/type_traits/ext/common_type.hpp 2010-09-04 10:52:38 EDT (Sat, 04 Sep 2010)
@@ -45,19 +45,19 @@
 #define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type"
 #endif
 
+#if defined(BOOST_NO_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
 #include <boost/type_traits/ext/detail/common_type.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/type_traits/is_void.hpp>
-#include <boost/type_traits/is_reference.hpp>
-#include <boost/type_traits/is_pointer.hpp>
 #include <boost/type_traits/remove_cv.hpp>
+#endif
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/declval.hpp>
 
 //----------------------------------------------------------------------------//
 // //
 // C++03 implementation of //
 // 20.6.7 Other transformations [meta.trans.other] //
 // Written by Howard Hinnant //
-// Adapted for Boost by Beman Dawes //
+// Adapted for Boost by Beman Dawes, Vicente Botet and Jeffrey Hellrung //
 // //
 //----------------------------------------------------------------------------//
 
@@ -92,39 +92,7 @@
     };
 
 // 2 args
-
-
- namespace type_traits_detail {
-
- template <typename T,
- bool = !is_reference<T>::value && ! is_pointer<T>::value && !is_void<T>::value>
- struct add_rvalue_reference_helper
- { typedef T type; };
-
- template <typename T>
- struct add_rvalue_reference_helper<T, true>
- {
-#if !defined(BOOST_NO_RVALUE_REFERENCES)
- typedef T&& type;
-#else
- typedef T type;
-#endif
- };
-
- /// add_rvalue_reference
- template <typename T>
- struct add_rvalue_reference
- : public add_rvalue_reference_helper<T>
- { };
-
- template <typename T>
- struct add_rvalue_reference<T&>
- { typedef T& type;
- };
-
-
- template <typename T>
- typename add_rvalue_reference<T>::type declval();
+namespace type_traits_detail {
 
     template <class T, class U>
     struct common_type_2
@@ -133,36 +101,22 @@
         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 declval_bool(); // workaround gcc bug; not required by std
- static typename add_rvalue_reference_helper<T>::type declval_T(); // workaround gcc bug; not required by std
- static typename add_rvalue_reference_helper<U>::type declval_U(); // workaround gcc bug; not required by std
+ static typename add_rvalue_reference<T>::type declval_T(); // workaround gcc bug; not required by std
+ static typename add_rvalue_reference<U>::type declval_U(); // workaround gcc bug; not required by std
 
 #if !defined(BOOST_NO_DECLTYPE)
     public:
         typedef decltype(declval<bool>() ? declval<T>() : declval<U>()) type;
 #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
-#if 0
- typedef char (&yes)[1];
- typedef char (&no)[2];
- //~ static yes deduce(typename add_rvalue_reference_helper<T>::type);
- //~ static no deduce(typename add_rvalue_reference_helper<U>::type);
- static yes deduce(T);
- static no deduce(U);
- public:
- typedef typename mpl::if_c<
- sizeof( deduce( declval_bool() ? declval_T() : declval_U() ) ) == sizeof( yes ),
- T,
- U
- >::type type;
-#else
     public:
     typedef typename detail_type_traits_common_type::common_type_impl<
           typename remove_cv<T>::type,
           typename remove_cv<U>::type
>::type type;
-#endif
 #else
     public:
- typedef BOOST_TYPEOF_TPL(declval_bool() ? declval_T() : declval_U()) type;
+ //~ typedef BOOST_TYPEOF_TPL(declval_bool() ? declval_T() : declval_U()) type;
+ typedef BOOST_TYPEOF_TPL(declval<bool>() ? declval<T>() : declval<U>()) type;
 #endif
     };
 

Added: sandbox/chrono/boost/type_traits/ext/declval.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/type_traits/ext/declval.hpp 2010-09-04 10:52:38 EDT (Sat, 04 Sep 2010)
@@ -0,0 +1,44 @@
+// common_type.hpp ---------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
+#define BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
+
+#include <boost/config.hpp>
+
+//----------------------------------------------------------------------------//
+
+#include <boost/type_traits/add_rvalue_reference.hpp>
+
+//----------------------------------------------------------------------------//
+// //
+// C++03 implementation of //
+// Written by Vicente J. Botet Escriba //
+//~ 20.3.4 Function template declval [declval]
+//~ 1 The library provides the function template declval to simplify the definition of expressions which occur as
+//~ unevaluated operands.
+//~ 2 Remarks: If this function is used, the program is ill-formed.
+//~ 3 Remarks: The template parameter T of declval may be an incomplete type.
+//~ [ Example:
+
+//~ template <class To, class From>
+//~ decltype(static_cast<To>(declval<From>())) convert(From&&);
+
+//~ declares a function template convert which only participats in overloading if the type From can be
+//~ explicitly converted to type To. For another example see class template common_type (20.7.6.6). —end
+//~ example ]
+// //
+//----------------------------------------------------------------------------//
+
+namespace boost {
+
+ template <typename T>
+ typename add_rvalue_reference<T>::type declval(); //noexcept; // as unevaluated operand
+
+} // namespace boost
+
+#endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP

Modified: sandbox/chrono/boost/type_traits/ext/detail/common_type.hpp
==============================================================================
--- sandbox/chrono/boost/type_traits/ext/detail/common_type.hpp (original)
+++ sandbox/chrono/boost/type_traits/ext/detail/common_type.hpp 2010-09-04 10:52:38 EDT (Sat, 04 Sep 2010)
@@ -44,6 +44,7 @@
 #include <boost/type_traits/make_unsigned.hpp>
 #include <boost/type_traits/remove_cv.hpp>
 #include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/declval.hpp>
 
 namespace boost
 {
@@ -87,16 +88,6 @@
 { };
 
 /*******************************************************************************
- * anon_obj<T>() -> T
- *
- * This dummy function only serves to generate an expression of type T. This
- * will be an rvalue expression if T is a non-reference type, and will be an
- * lvalue expression if T is a reference type.
- ******************************************************************************/
-
-template< class T > T anon_obj();
-
-/*******************************************************************************
  * struct sizeof_t<N>
  * typedef ... yes_type
  * typedef ... no_type
@@ -186,7 +177,7 @@
  *
  * These classes and structs implement the logic behind common_type, which goes
  * roughly as follows. Let C be the type of the conditional expression
- * anon_obj< bool >() ? anon_obj<T>() : anon_obj<U>()
+ * declval< bool >() ? declval<T>() : declval<U>()
  * if C is an rvalue, then:
  * let T' and U' be T and U stripped of reference- and cv-qualifiers
  * if T' and U' are pointer types, say, T' = V* and U' = W*, then:
@@ -230,7 +221,7 @@
>::type candidate_types;
     static const int best_candidate_index =
         sizeof( conversion_test_overloads< candidate_types >::apply(
- anon_obj< bool >() ? anon_obj<T>() : anon_obj<U>()
+ declval< bool >() ? declval<T>() : declval<U>()
         ) ) - 1;
 public:
     typedef typename select< candidate_types, best_candidate_index >::type type;
@@ -272,7 +263,7 @@
 template<
     class T, class U,
     bool = sizeof( ::boost::detail_type_traits_common_type::rvalue_test(
- anon_obj< bool >() ? anon_obj<T>() : anon_obj<U>()
+ declval< bool >() ? declval<T>() : declval<U>()
     ) ) == sizeof( yes_type )
>
 struct common_type_dispatch_on_rvalueness;
@@ -311,13 +302,6 @@
 
 } // namespace detail_type_traits_common_type
 
-//~ template< class T, class U >
-//~ struct common_type
- //~ : detail_type_traits_common_type::common_type_impl<
- //~ typename remove_cv<T>::type,
- //~ typename remove_cv<U>::type
- //~ >
-//~ { };
 
 } // namespace boost
 


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