Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66463 - sandbox/chrono/boost/static_string
From: vicente.botet_at_[hidden]
Date: 2010-11-08 17:04:26


Author: viboes
Date: 2010-11-08 17:04:21 EST (Mon, 08 Nov 2010)
New Revision: 66463
URL: http://svn.boost.org/trac/boost/changeset/66463

Log:
StaticString:
* Add ValueType template parameter to c_str
* Make value_type more general
Text files modified:
   sandbox/chrono/boost/static_string/c_str.hpp | 33 +++++++++++++---------
   sandbox/chrono/boost/static_string/value_type.hpp | 57 +++++++++++++++++++++++++++++++++++++--
   2 files changed, 73 insertions(+), 17 deletions(-)

Modified: sandbox/chrono/boost/static_string/c_str.hpp
==============================================================================
--- sandbox/chrono/boost/static_string/c_str.hpp (original)
+++ sandbox/chrono/boost/static_string/c_str.hpp 2010-11-08 17:04:21 EST (Mon, 08 Nov 2010)
@@ -1,9 +1,14 @@
 // c_str.hpp --------------------------------------------------------------//
 
-// Copyright 2010 Vicente J. Botet Escriba
+// Copyright Eric Niebler 2009
+// Copyright Vicente J. Botet Escriba 2010
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/mpl for documentation.
 
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
 
 
 #ifndef BOOST_STATIC_STRING_C_STR_HPP
@@ -49,37 +54,37 @@
     };
 }
 
-template<typename Sequence>
+template<typename Sequence, typename ValueType=typename value_type<Sequence>::type>
 struct c_str
 {
-// typedef typename value_type<Sequence>::type value_type;
     typedef typename mpl::end<Sequence>::type iend;
     typedef typename mpl::begin<Sequence>::type i0;
- #define BOOST_STATIC_STRING_C_STR_M0(z, n, data) \
+ #define M0(z, n, data) \
     typedef \
         typename static_string::detail::next_unless<BOOST_PP_CAT(i, n), iend>::type \
     BOOST_PP_CAT(i, BOOST_PP_INC(n));
     
- BOOST_PP_REPEAT(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE, BOOST_STATIC_STRING_C_STR_M0, ~)
+ BOOST_PP_REPEAT(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE, M0, ~)
     
- #undef BOOST_STATIC_STRING_C_STR_M0
+ #undef M0
 
     typedef c_str type;
- static typename value_type<Sequence>::type const value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1];
+ static ValueType const value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1];
 };
 
-template<typename Sequence>
-typename value_type<Sequence>::type const c_str<Sequence>::value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1] =
+template<typename Sequence, typename ValueType>
+ValueType const c_str<Sequence, ValueType>::value[BOOST_STATIC_STRING_LIMIT_C_STR_SIZE+1] =
 {
- #define BOOST_STATIC_STRING_C_STR_M0(z, n, data) \
+ #define M0(z, n, data) \
     static_string::detail::deref_unless<typename value_type<Sequence>::type, BOOST_PP_CAT(i, n), iend>::type::value,
         
- BOOST_PP_REPEAT(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE, BOOST_STATIC_STRING_C_STR_M0, ~)
+ BOOST_PP_REPEAT(BOOST_STATIC_STRING_LIMIT_C_STR_SIZE, M0, ~)
     
- #undef BOOST_STATIC_STRING_C_STR_M0
+ #undef M0
     mpl::integral_c<typename value_type<Sequence>::type, 0>::type::value
 };
 
+
 } // namespace static_string
 } // namespace boost
 

Modified: sandbox/chrono/boost/static_string/value_type.hpp
==============================================================================
--- sandbox/chrono/boost/static_string/value_type.hpp (original)
+++ sandbox/chrono/boost/static_string/value_type.hpp 2010-11-08 17:04:21 EST (Mon, 08 Nov 2010)
@@ -1,6 +1,12 @@
 // value_type.hpp --------------------------------------------------------------//
 
 // Copyright 2010 Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/mpl for documentation.
 
 // Distributed under the Boost Software License, Version 1.0.
 // See http://www.boost.org/LICENSE_1_0.txt
@@ -9,14 +15,59 @@
 #ifndef BOOST_STATIC_STRING_VALUE_TYPE_HPP
 #define BOOST_STATIC_STRING_VALUE_TYPE_HPP
 
+#include <boost/mpl/front.hpp>
+#include <boost/mpl/has_xxx.hpp>
+
 namespace boost {
 namespace static_string {
 
-template<typename Sequence>
-struct value_type {
- typedef typename Sequence::value_type type;
+template< typename X >
+struct value_type;
+
+namespace detail {
+
+BOOST_MPL_HAS_XXX_TRAIT_DEF( value_type )
+
+template< typename X, bool IsSeq=static_string::detail::has_value_type<X>::value >
+struct value_type_impl_is_sequence;
+
+
+template< typename Seq>
+struct value_type_impl_is_sequence<Seq, true>
+{
+ typedef typename value_type<typename mpl::front<Seq>::type >::type type;
+};
+
+//template< typename X>
+//struct value_type_impl_is_sequence<X, false>,
+//{
+// typedef typename value_type< typename mpl::front<X>::type >::type type;
+//};
+
+template< typename X, bool HasValueType=static_string::detail::has_value_type<X>::value >
+struct value_type_impl_has_value_type;
+
+template< typename X>
+struct value_type_impl_has_value_type<X,true>
+{
+ typedef typename X::value_type type;
+};
+
+template< typename X >
+struct value_type_impl_has_value_type<X,false>
+{
+ typedef typename value_type< typename mpl::front<X>::type >::type type;
 };
 
+}
+
+template< typename X >
+struct value_type
+ : static_string::detail::value_type_impl_has_value_type< X >
+{
+};
+
+
 } // namespace static_string
 } // 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