to_string.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // boost/chrono/utility/to_string.hpp
  2. //
  3. // Copyright 2011 Vicente J. Botet Escriba
  4. // Use, modification and distribution are subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt).
  7. #ifndef BOOST_CHRONO_UTILITY_TO_STRING_HPP
  8. #define BOOST_CHRONO_UTILITY_TO_STRING_HPP
  9. #include <boost/chrono/config.hpp>
  10. #include <string>
  11. #include <sstream>
  12. namespace boost
  13. {
  14. namespace chrono
  15. {
  16. template <typename CharT, typename T>
  17. std::basic_string<CharT> to_basic_string(T const&v) {
  18. std::basic_stringstream<CharT> sstr;
  19. sstr << v;
  20. return sstr.str();
  21. }
  22. template <typename T>
  23. std::string to_string(T const&v) {
  24. return to_basic_string<char>(v);
  25. }
  26. #ifndef BOOST_NO_STD_WSTRING
  27. template <typename T>
  28. std::wstring to_wstring(T const&v) {
  29. return to_basic_string<wchar_t>(v);
  30. }
  31. #endif
  32. #if BOOST_CHRONO_HAS_UNICODE_SUPPORT
  33. template <typename T>
  34. std::basic_string<char16_t> to_u16string(T const&v) {
  35. return to_basic_string<char16_t>(v);
  36. }
  37. template <typename T>
  38. std::basic_string<char32_t> to_u32string(T const&v) {
  39. return to_basic_string<char32_t>(v);
  40. }
  41. #endif
  42. } // chrono
  43. } // boost
  44. #endif // header