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