]>
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-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.
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>
14 #include <boost/detail/lightweight_test.hpp>
19 namespace arg
= boost::cnv::parameter
;
22 main(int, char const* [])
24 boost::cnv::printf cnv
;
26 string
const not_int_str
= "not an int";
27 string
const std_str
= "-11";
28 char const* const c_str
= "-12";
30 BOOST_TEST( -1 == convert
<int>(not_int_str
, cnv
).value_or(-1));
31 BOOST_TEST(-11 == convert
<int>(std_str
, cnv
).value_or(-1));
32 BOOST_TEST(-12 == convert
<int>(c_str
, cnv
).value_or(-1));
34 BOOST_TEST("255" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::dec
)).value());
35 BOOST_TEST( "ff" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::hex
)).value());
36 BOOST_TEST("377" == convert
<std::string
>(255, cnv(arg::base
= boost::cnv::base::oct
)).value());
38 string s01
= convert
<string
>(12.3456, cnv(arg::precision
= 6)).value();
39 string s02
= convert
<string
>(12.3456, cnv(arg::precision
= 3)).value();
41 BOOST_TEST(s01
== "12.345600");
42 BOOST_TEST(s02
== "12.346");
44 return boost::report_errors();