// Copyright (c) 2009-2014 Vladimir Batov. // Use, modification and distribution are subject to the Boost Software License, // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./example.hpp" //[lexical_cast_headers1 #include #include using std::string; //] void example::lexical_cast() { //[lexical_cast_example1 boost::cnv::lexical_cast cnv; int i1 = boost::lexical_cast("123"); // Throws if the conversion fails int i2 = boost::convert("123", cnv).value(); // Throws if the conversion fails int i3 = boost::convert("uhm", cnv).value_or(-1); // Returns -1 if the conversion fails string s1 = boost::lexical_cast(123); string s2 = boost::convert(123, cnv).value(); BOOST_TEST(i1 == 123); BOOST_TEST(i2 == 123); BOOST_TEST(i3 == -1); BOOST_TEST(s1 == "123"); BOOST_TEST(s2 == "123"); //] }