]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/example/lexical_cast.cpp
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.
5 //[lexical_cast_headers1
6 #include <boost/convert.hpp>
7 #include <boost/convert/lexical_cast.hpp>
8 #include <boost/detail/lightweight_test.hpp>
12 using boost::lexical_cast
;
14 struct boost::cnv::by_default
: boost::cnv::lexical_cast
{};
18 main(int, char const* [])
20 //[lexical_cast_example1
21 int i1
= lexical_cast
<int>("123"); // Throws if the conversion fails.
22 int i2
= convert
<int>("123").value(); // Throws if the conversion fails.
23 int i3
= convert
<int>("uhm").value_or(-1); // Returns -1 if the conversion fails.
24 string s1
= lexical_cast
<string
>(123);
25 string s2
= convert
<string
>(123).value();
27 BOOST_TEST(i1
== 123);
28 BOOST_TEST(i2
== 123);
30 BOOST_TEST(s1
== "123");
31 BOOST_TEST(s2
== "123");
34 return boost::report_errors();