]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/test/printf_converter.cpp
1 // Boost.Convert test and usage example
2 // Copyright (c) 2009-2020 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.
8 #if defined(BOOST_CONVERT_IS_NOT_SUPPORTED)
9 int main(int, char const* []) { return 0; }
12 #include <boost/convert.hpp>
13 #include <boost/convert/printf.hpp>
18 namespace arg
= boost::cnv::parameter
;
21 main(int, char const* [])
23 boost::cnv::printf cnv
;
25 string
const not_int_str
= "not an int";
26 string
const std_str
= "-11";
27 char const* const c_str
= "-12";
29 BOOST_TEST( -1 == convert
<int>(not_int_str
, cnv
).value_or(-1));
30 BOOST_TEST(-11 == convert
<int>(std_str
, cnv
).value_or(-1));
31 BOOST_TEST(-12 == convert
<int>(c_str
, cnv
).value_or(-1));
33 BOOST_TEST("255" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::dec
)).value());
34 BOOST_TEST( "ff" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::hex
)).value());
35 BOOST_TEST("377" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::oct
)).value());
37 string s01
= convert
<string
>(12.3456, cnv(arg::precision
= 6)).value();
38 string s02
= convert
<string
>(12.3456, cnv(arg::precision
= 3)).value();
40 BOOST_TEST(s01
== "12.345600");
41 BOOST_TEST(s02
== "12.346");
43 return boost::report_errors();