fix doc example typo
[boost.git] / boost / exception / to_string.hpp
blob5d88efa4676a007e3f30cae7fdd4b93ee440d3ff
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_7E48761AD92811DC9011477D56D89593
7 #define UUID_7E48761AD92811DC9011477D56D89593
9 #include <boost/utility/enable_if.hpp>
10 #include <boost/exception/detail/is_output_streamable.hpp>
11 #include <sstream>
13 namespace
14 boost
16 namespace
17 to_string_detail
19 template <class T>
20 typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
22 template <class,bool IsOutputStreamable>
23 struct has_to_string_impl;
25 template <class T>
26 struct
27 has_to_string_impl<T,true>
29 enum e { value=1 };
32 template <class T>
33 struct
34 has_to_string_impl<T,false>
36 static T const & f();
37 enum e { value=1!=sizeof(to_string(f())) };
41 template <class T>
42 inline
43 typename enable_if<is_output_streamable<T>,std::string>::type
44 to_string( T const & x )
46 std::ostringstream out;
47 out << x;
48 return out.str();
51 template <class T>
52 struct
53 has_to_string
55 enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
58 template <class T,class U>
59 inline
60 std::string
61 to_string( std::pair<T,U> const & x )
63 return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
66 inline
67 std::string
68 to_string( std::exception const & x )
70 return x.what();
74 #endif