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

source code of include/boost/exception/to_string.hpp