to_string.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2007-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
  5. +------------------------------------------------------------------------------+
  6. Distributed under the Boost Software License, Version 1.0.
  7. (See accompanying file LICENCE.txt or copy at
  8. http://www.boost.org/LICENSE_1_0.txt)
  9. +-----------------------------------------------------------------------------*/
  10. /*-----------------------------------------------------------------------------
  11. Function-templates for discrete Datatypes like int, unsigned or
  12. any class that provides a ++ operator c.f. iterators
  13. -----------------------------------------------------------------------------*/
  14. #ifndef BOOST_ICL_TO_STRING_HPP_JOFA_000712
  15. #define BOOST_ICL_TO_STRING_HPP_JOFA_000712
  16. #include <stdio.h>
  17. #include <string>
  18. #include <sstream>
  19. namespace boost{ namespace icl
  20. {
  21. /// Static class template for the string representation of values
  22. template <class Type>
  23. struct to_string
  24. {
  25. /** Converts all values of types to std::string that implement an operator << */
  26. static std::string apply(const Type& value)
  27. {
  28. std::stringstream repr;
  29. repr << value;
  30. return repr.str();
  31. }
  32. };
  33. }} // namespace boost icl
  34. #endif