forked from boostorg/exception
to_string fixes
[SVN r44164]
This commit is contained in:
@ -6,22 +6,62 @@
|
||||
#ifndef UUID_7E48761AD92811DC9011477D56D89593
|
||||
#define UUID_7E48761AD92811DC9011477D56D89593
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/exception/detail/is_output_streamable.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
namespace
|
||||
exception_detail
|
||||
{
|
||||
template <bool>
|
||||
struct
|
||||
has_to_string_dispatch
|
||||
{
|
||||
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>
|
||||
std::string
|
||||
to_string( T const & x )
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << x;
|
||||
return out.str();
|
||||
}
|
||||
char to_string( T const &, typename disable_if< is_output_streamable<T> >::type * = 0 );
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
has_to_string_impl
|
||||
{
|
||||
enum e { value=has_to_string_dispatch<1!=sizeof(to_string(*(T*)0))>::value };
|
||||
};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct
|
||||
has_to_string
|
||||
{
|
||||
enum e { value=exception_detail::has_to_string_impl<T>::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user