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