lexical_cast.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2009-2016 Vladimir Batov.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
  4. #ifndef BOOST_CONVERT_LEXICAL_CAST_HPP
  5. #define BOOST_CONVERT_LEXICAL_CAST_HPP
  6. #include <boost/lexical_cast.hpp>
  7. namespace boost { namespace cnv
  8. {
  9. struct lexical_cast;
  10. }}
  11. /// @brief boost::lexical_cast-based converter
  12. /// @details The purpose of the converter is to
  13. /// * Make use of the boost::lexical_cast functionality and performance that many people have become
  14. /// accustomed to and comfortable with;
  15. /// * Demonstrate how existing independent conversion/transformation-related facilities might be
  16. // incorporated in to the Boost.Convert framework.
  17. ///
  18. /// The converter can easily replace boost::lexical_cast, adding flexibility and convenience.
  19. struct boost::cnv::lexical_cast
  20. {
  21. template<typename TypeOut, typename TypeIn>
  22. void
  23. operator()(TypeIn const& value_in, boost::optional<TypeOut>& result_out) const
  24. {
  25. try
  26. {
  27. result_out = boost::lexical_cast<TypeOut>(value_in);
  28. }
  29. catch (boost::bad_lexical_cast const&)
  30. {
  31. }
  32. }
  33. };
  34. #endif // BOOST_CONVERT_LEXICAL_CAST_HPP