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