diff --git a/include/boost/exception/detail/is_output_streamable.hpp b/include/boost/exception/detail/is_output_streamable.hpp index badf4da..079ab99 100644 --- a/include/boost/exception/detail/is_output_streamable.hpp +++ b/include/boost/exception/detail/is_output_streamable.hpp @@ -12,7 +12,7 @@ namespace boost { namespace - exception_detail + to_string_detail { template struct @@ -43,7 +43,7 @@ boost struct is_output_streamable { - enum e { value=exception_detail::is_output_streamable_impl::value }; + enum e { value=to_string_detail::is_output_streamable_impl::value }; }; } diff --git a/include/boost/exception/to_string.hpp b/include/boost/exception/to_string.hpp index 897f6f0..443ad6d 100644 --- a/include/boost/exception/to_string.hpp +++ b/include/boost/exception/to_string.hpp @@ -14,55 +14,44 @@ namespace boost { namespace - exception_detail + to_string_detail { - template - struct - has_to_string_dispatch + template + typename disable_if,char>::type to_string( T const & ); + + template + struct has_to_string_impl; + + template + struct + has_to_string_impl { enum e { value=1 }; }; - template <> - struct - has_to_string_dispatch - { - enum e { value=0 }; - }; - - template - std::string - to_string( T const & x, typename enable_if< is_output_streamable >::type * = 0 ) - { - std::ostringstream out; - out << x; - return out.str(); - } - - template - char to_string( T const &, typename disable_if< is_output_streamable >::type * = 0 ); - template struct - has_to_string_impl + has_to_string_impl { - enum e { value=has_to_string_dispatch<1!=sizeof(to_string(*(T*)0))>::value }; + enum e { value=1!=sizeof(to_string(*(T*)0)) }; }; } template + typename enable_if,std::string>::type + to_string( T const & x ) + { + std::ostringstream out; + out << x; + return out.str(); + } + + template struct has_to_string { - enum e { value=exception_detail::has_to_string_impl::value }; + enum e { value=to_string_detail::has_to_string_impl::value>::value }; }; - - template - std::string - to_string( T const & x, typename enable_if< is_output_streamable >::type * = 0 ) - { - return exception_detail::to_string(x); - } } #endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 879028b..a08d0fc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -9,6 +9,7 @@ import testing ; #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 ; diff --git a/test/has_to_string_test.cpp b/test/has_to_string_test.cpp new file mode 100644 index 0000000..3d6fb85 --- /dev/null +++ b/test/has_to_string_test.cpp @@ -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 +#include + +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::value ); + BOOST_TEST( has_to_string::value ); + BOOST_TEST( has_to_string::value ); + BOOST_TEST( has_to_string::value ); + return boost::report_errors(); + } diff --git a/test/to_string_test.cpp b/test/to_string_test.cpp index f722378..c2ea856 100644 --- a/test/to_string_test.cpp +++ b/test/to_string_test.cpp @@ -49,10 +49,6 @@ int main() { using namespace boost; - BOOST_TEST( !has_to_string::value ); - BOOST_TEST( has_to_string::value ); - BOOST_TEST( has_to_string::value ); - BOOST_TEST( has_to_string::value ); BOOST_TEST( "c2"==to_string(n2::c2()) ); BOOST_TEST( "c3"==to_string(n3::c3()) ); BOOST_TEST( "42"==to_string(42) );