to_string adjustments

[SVN r44192]
This commit is contained in:
Emil Dotchevski
2008-04-11 18:34:46 +00:00
parent 3c7f53176f
commit 761ae0bc1e
5 changed files with 82 additions and 39 deletions

View File

@ -14,55 +14,44 @@ namespace
boost
{
namespace
exception_detail
to_string_detail
{
template <bool>
struct
has_to_string_dispatch
template <class T>
typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
template <class,bool IsOutputStreamable>
struct has_to_string_impl;
template <class T>
struct
has_to_string_impl<T,true>
{
enum e { value=1 };
};
template <>
struct
has_to_string_dispatch<false>
{
enum e { value=0 };
};
template <class T>
std::string
to_string( T const & x, typename enable_if< is_output_streamable<T> >::type * = 0 )
{
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 );
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