Chris@16
|
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
Chris@16
|
2
|
Chris@16
|
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef UUID_7E48761AD92811DC9011477D56D89593
|
Chris@16
|
7 #define UUID_7E48761AD92811DC9011477D56D89593
|
Chris@16
|
8 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
9 #pragma GCC system_header
|
Chris@16
|
10 #endif
|
Chris@16
|
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
12 #pragma warning(push,1)
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
16 #include <boost/exception/detail/is_output_streamable.hpp>
|
Chris@16
|
17 #include <sstream>
|
Chris@16
|
18
|
Chris@16
|
19 namespace
|
Chris@16
|
20 boost
|
Chris@16
|
21 {
|
Chris@16
|
22 template <class T,class U>
|
Chris@16
|
23 std::string to_string( std::pair<T,U> const & );
|
Chris@16
|
24 std::string to_string( std::exception const & );
|
Chris@16
|
25
|
Chris@16
|
26 namespace
|
Chris@16
|
27 to_string_detail
|
Chris@16
|
28 {
|
Chris@16
|
29 template <class T>
|
Chris@16
|
30 typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
|
Chris@16
|
31 using boost::to_string;
|
Chris@16
|
32
|
Chris@16
|
33 template <class,bool IsOutputStreamable>
|
Chris@16
|
34 struct has_to_string_impl;
|
Chris@16
|
35
|
Chris@16
|
36 template <class T>
|
Chris@16
|
37 struct
|
Chris@16
|
38 has_to_string_impl<T,true>
|
Chris@16
|
39 {
|
Chris@16
|
40 enum e { value=1 };
|
Chris@16
|
41 };
|
Chris@16
|
42
|
Chris@16
|
43 template <class T>
|
Chris@16
|
44 struct
|
Chris@16
|
45 has_to_string_impl<T,false>
|
Chris@16
|
46 {
|
Chris@16
|
47 static T const & f();
|
Chris@16
|
48 enum e { value=1!=sizeof(to_string(f())) };
|
Chris@16
|
49 };
|
Chris@16
|
50 }
|
Chris@16
|
51
|
Chris@16
|
52 template <class T>
|
Chris@16
|
53 inline
|
Chris@16
|
54 typename enable_if<is_output_streamable<T>,std::string>::type
|
Chris@16
|
55 to_string( T const & x )
|
Chris@16
|
56 {
|
Chris@16
|
57 std::ostringstream out;
|
Chris@16
|
58 out << x;
|
Chris@16
|
59 return out.str();
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 template <class T>
|
Chris@16
|
63 struct
|
Chris@16
|
64 has_to_string
|
Chris@16
|
65 {
|
Chris@16
|
66 enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69 template <class T,class U>
|
Chris@16
|
70 inline
|
Chris@16
|
71 std::string
|
Chris@16
|
72 to_string( std::pair<T,U> const & x )
|
Chris@16
|
73 {
|
Chris@16
|
74 return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 inline
|
Chris@16
|
78 std::string
|
Chris@16
|
79 to_string( std::exception const & x )
|
Chris@16
|
80 {
|
Chris@16
|
81 return x.what();
|
Chris@16
|
82 }
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
86 #pragma warning(pop)
|
Chris@16
|
87 #endif
|
Chris@16
|
88 #endif
|