]> git.lyx.org Git - lyx.git/blob - boost/boost/exception/to_string.hpp
update to boost 1.39: update existing files
[lyx.git] / boost / boost / exception / to_string.hpp
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 UUID_7E48761AD92811DC9011477D56D89593
7 #define UUID_7E48761AD92811DC9011477D56D89593
8
9 #include <boost/utility/enable_if.hpp>
10 #include <boost/exception/detail/is_output_streamable.hpp>
11 #include <sstream>
12
13 namespace
14 boost
15     {
16     namespace
17     to_string_detail
18         {
19         template <class T>
20         typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
21
22         template <class,bool IsOutputStreamable>
23         struct has_to_string_impl;
24
25         template <class T>
26         struct
27         has_to_string_impl<T,true>
28             {
29             enum e { value=1 };
30             };
31
32         template <class T>
33         struct
34         has_to_string_impl<T,false>
35             {
36             static T const & f();
37             enum e { value=1!=sizeof(to_string(f())) };
38             };
39         }
40
41     template <class T>
42     inline
43     typename enable_if<is_output_streamable<T>,std::string>::type
44     to_string( T const & x )
45         {
46         std::ostringstream out;
47         out << x;
48         return out.str();
49         }
50
51     template <class T>
52     struct
53     has_to_string
54         {
55         enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
56         };
57
58     template <class T,class U>
59     inline
60     std::string
61     to_string( std::pair<T,U> const & x )
62         {
63         return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
64         }
65
66     inline
67     std::string
68     to_string( std::exception const & x )
69         {
70         return x.what();
71         }
72     }
73
74 #endif