]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/example/default_converter.cpp
1 // Boost.Convert test and usage example
2 // Copyright (c) 2009-2016 Vladimir Batov.
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
6 #include <boost/convert.hpp>
7 #include <boost/convert/stream.hpp>
8 #include <boost/detail/lightweight_test.hpp>
10 #ifdef ONLY_FOR_DEMONSTRATION_PURPOSES
11 //[default_converter_declaration_simple
12 struct boost::cnv::by_default
: public boost::cnv::cstream
{};
15 //[default_converter_declaration_formatted
16 struct boost::cnv::by_default
: public boost::cnv::cstream
18 by_default() { (*this)(std::uppercase
)(std::hex
); }
23 main(int, char const* [])
25 //[default_converter_example1
26 // No explicit converter provided. boost::cnv::by_default is used.
27 int i
= boost::convert
<int>("F").value_or(-1);
28 std::string s
= boost::convert
<std::string
>(255).value_or("bad");
30 // 'i' and 's' are converted using boost::cnv::cstream
31 // with std::uppercase and std::hex formatting applied.
33 BOOST_TEST(i
== 15); // 15(10) = F(16)
34 BOOST_TEST(s
== "FF"); // 255(10) = FF(16)
37 return boost::report_errors();