lexical_cast.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2009-2020 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 { struct lexical_cast; }}
  8. /// @brief boost::lexical_cast-based converter
  9. /// @details The purpose of the converter is to
  10. /// * Make use of the boost::lexical_cast functionality and performance that many people have become
  11. /// accustomed to and comfortable with;
  12. /// * Demonstrate how existing independent conversion/transformation-related facilities might be
  13. // incorporated in to the Boost.Convert framework.
  14. ///
  15. /// The converter can easily replace boost::lexical_cast, adding flexibility and convenience.
  16. struct boost::cnv::lexical_cast
  17. {
  18. template<typename TypeOut, typename TypeIn>
  19. void
  20. operator()(TypeIn const& value_in, boost::optional<TypeOut>& result_out) const
  21. {
  22. try
  23. {
  24. result_out = boost::lexical_cast<TypeOut>(value_in);
  25. }
  26. catch (boost::bad_lexical_cast const&)
  27. {
  28. }
  29. }
  30. };
  31. #endif // BOOST_CONVERT_LEXICAL_CAST_HPP