lexical_cast.hpp 600 B

1234567891011121314151617181920212223
  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. namespace boost
  5. {
  6. /// A quick replacement for boost::lexical_cast - should work for all types a stringstream can handle
  7. template <typename TargetType, typename SourceType>
  8. TargetType lexical_cast( const SourceType& source)
  9. {
  10. std::stringstream stream;
  11. TargetType result;
  12. stream << source;
  13. stream >> result;
  14. return result;
  15. }
  16. } // namespace boost
  17. #endif // __AI_BOOST_WORKAROUND_LEXICAL_CAST