lexical_cast.hpp 626 B

1234567891011121314151617181920212223242526
  1. /// A quick replacement for boost::lexical_cast for all the Boost haters out there
  2. #ifndef __AI_BOOST_WORKAROUND_LEXICAL_CAST
  3. #define __AI_BOOST_WORKAROUND_LEXICAL_CAST
  4. #include <sstream>
  5. namespace boost
  6. {
  7. /// A quick replacement for boost::lexical_cast - should work for all types a stringstream can handle
  8. template <typename TargetType, typename SourceType>
  9. TargetType lexical_cast( const SourceType& source)
  10. {
  11. std::stringstream stream;
  12. TargetType result;
  13. stream << source;
  14. stream >> result;
  15. return result;
  16. }
  17. } // namespace boost
  18. #endif // __AI_BOOST_WORKAROUND_LEXICAL_CAST