Boost logo

Boost-Commit :

From: emil_at_[hidden]
Date: 2008-04-11 14:34:47


Author: emildotchevski
Date: 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
New Revision: 44192
URL: http://svn.boost.org/trac/boost/changeset/44192

Log:
to_string adjustments
Added:
   trunk/libs/exception/test/has_to_string_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/exception/detail/is_output_streamable.hpp | 4 +-
   trunk/boost/exception/to_string.hpp | 53 +++++++++++++++------------------------
   trunk/libs/exception/test/Jamfile.v2 | 1
   trunk/libs/exception/test/to_string_test.cpp | 4 ---
   4 files changed, 24 insertions(+), 38 deletions(-)

Modified: trunk/boost/exception/detail/is_output_streamable.hpp
==============================================================================
--- trunk/boost/exception/detail/is_output_streamable.hpp (original)
+++ trunk/boost/exception/detail/is_output_streamable.hpp 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
@@ -12,7 +12,7 @@
 boost
     {
         namespace
- exception_detail
+ to_string_detail
                 {
                 template <bool>
                 struct
@@ -43,7 +43,7 @@
     struct
         is_output_streamable
                 {
- enum e { value=exception_detail::is_output_streamable_impl<T,CharT,Traits>::value };
+ enum e { value=to_string_detail::is_output_streamable_impl<T,CharT,Traits>::value };
                 };
     }
 

Modified: trunk/boost/exception/to_string.hpp
==============================================================================
--- trunk/boost/exception/to_string.hpp (original)
+++ trunk/boost/exception/to_string.hpp 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
@@ -14,55 +14,44 @@
 boost
     {
         namespace
- exception_detail
+ to_string_detail
                 {
- template <bool>
- struct
- has_to_string_dispatch
- {
- enum e { value=1 };
- };
+ template <class T>
+ typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
 
- template <>
- struct
- has_to_string_dispatch<false>
- {
- enum e { value=0 };
- };
+ template <class,bool IsOutputStreamable>
+ struct has_to_string_impl;
 
                 template <class T>
- std::string
- to_string( T const & x, typename enable_if< is_output_streamable<T> >::type * = 0 )
+ struct
+ has_to_string_impl<T,true>
                         {
- std::ostringstream out;
- out << x;
- return out.str();
- }
-
- template <class T>
- char to_string( T const &, typename disable_if< is_output_streamable<T> >::type * = 0 );
+ enum e { value=1 };
+ };
 
                 template <class T>
         struct
- has_to_string_impl
+ has_to_string_impl<T,false>
                         {
- enum e { value=has_to_string_dispatch<1!=sizeof(to_string(*(T*)0))>::value };
+ enum e { value=1!=sizeof(to_string(*(T*)0)) };
                         };
                 }
 
         template <class T>
+ typename enable_if<is_output_streamable<T>,std::string>::type
+ to_string( T const & x )
+ {
+ std::ostringstream out;
+ out << x;
+ return out.str();
+ }
+
+ template <class T>
     struct
         has_to_string
                 {
- enum e { value=exception_detail::has_to_string_impl<T>::value };
+ enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
                 };
-
- template <class T>
- std::string
- to_string( T const & x, typename enable_if< is_output_streamable<T> >::type * = 0 )
- {
- return exception_detail::to_string(x);
- }
     }
 
 #endif

Modified: trunk/libs/exception/test/Jamfile.v2
==============================================================================
--- trunk/libs/exception/test/Jamfile.v2 (original)
+++ trunk/libs/exception/test/Jamfile.v2 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
@@ -9,6 +9,7 @@
 
 #to_string
 run is_output_streamable_test.cpp ;
+run has_to_string_test.cpp ;
 run to_string_test.cpp ;
 run to_string_stub_test.cpp ;
 compile-fail to_string_fail.cpp ;

Added: trunk/libs/exception/test/has_to_string_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/exception/test/has_to_string_test.cpp 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
@@ -0,0 +1,57 @@
+//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
+
+//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)
+
+#include <boost/exception/to_string.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+namespace
+n1
+ {
+ struct
+ c1
+ {
+ };
+ }
+
+namespace
+n2
+ {
+ struct
+ c2
+ {
+ };
+
+ std::string
+ to_string( c2 const & )
+ {
+ return "c2";
+ }
+ }
+
+namespace
+n3
+ {
+ struct
+ c3
+ {
+ };
+
+ std::ostream &
+ operator<<( std::ostream & s, c3 const & )
+ {
+ return s << "c3";
+ }
+ }
+
+int
+main()
+ {
+ using namespace boost;
+ BOOST_TEST( !has_to_string<n1::c1>::value );
+ BOOST_TEST( has_to_string<n2::c2>::value );
+ BOOST_TEST( has_to_string<n3::c3>::value );
+ BOOST_TEST( has_to_string<int>::value );
+ return boost::report_errors();
+ }

Modified: trunk/libs/exception/test/to_string_test.cpp
==============================================================================
--- trunk/libs/exception/test/to_string_test.cpp (original)
+++ trunk/libs/exception/test/to_string_test.cpp 2008-04-11 14:34:46 EDT (Fri, 11 Apr 2008)
@@ -49,10 +49,6 @@
 main()
     {
         using namespace boost;
- BOOST_TEST( !has_to_string<n1::c1>::value );
- BOOST_TEST( has_to_string<n2::c2>::value );
- BOOST_TEST( has_to_string<n3::c3>::value );
- BOOST_TEST( has_to_string<int>::value );
         BOOST_TEST( "c2"==to_string(n2::c2()) );
         BOOST_TEST( "c3"==to_string(n3::c3()) );
         BOOST_TEST( "42"==to_string(42) );


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