to_string.hpp
Go to the documentation of this file.
00001 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
00002 
00003 //Distributed under the Boost Software License, Version 1.0. (See accompanying
00004 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef UUID_7E48761AD92811DC9011477D56D89593
00007 #define UUID_7E48761AD92811DC9011477D56D89593
00008 
00009 #include <boost/utility/enable_if.hpp>
00010 #include <boost/exception/detail/is_output_streamable.hpp>
00011 #include <sstream>
00012 
00013 namespace
00014 boost
00015     {
00016     namespace
00017     to_string_detail
00018         {
00019         template <class T>
00020         typename disable_if<is_output_streamable<T>,char>::type to_string( T const & );
00021 
00022         template <class,bool IsOutputStreamable>
00023         struct has_to_string_impl;
00024 
00025         template <class T>
00026         struct
00027         has_to_string_impl<T,true>
00028             {
00029             enum e { value=1 };
00030             };
00031 
00032         template <class T>
00033         struct
00034         has_to_string_impl<T,false>
00035             {
00036             static T const & f();
00037             enum e { value=1!=sizeof(to_string(f())) };
00038             };
00039         }
00040 
00041     template <class T>
00042     inline
00043     typename enable_if<is_output_streamable<T>,std::string>::type
00044     to_string( T const & x )
00045         {
00046         std::ostringstream out;
00047         out << x;
00048         return out.str();
00049         }
00050 
00051     template <class T>
00052     struct
00053     has_to_string
00054         {
00055         enum e { value=to_string_detail::has_to_string_impl<T,is_output_streamable<T>::value>::value };
00056         };
00057 
00058     template <class T,class U>
00059     inline
00060     std::string
00061     to_string( std::pair<T,U> const & x )
00062         {
00063         return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')';
00064         }
00065 
00066     inline
00067     std::string
00068     to_string( std::exception const & x )
00069         {
00070         return x.what();
00071         }
00072     }
00073 
00074 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29