]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/test/printf_converter.cpp
update sources to v12.2.3
[ceph.git] / 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.
5
6 #include "./test.hpp"
7
8 #if defined(BOOST_CONVERT_IS_NOT_SUPPORTED)
9 int main(int, char const* []) { return 0; }
10 #else
11
12 #include <boost/convert.hpp>
13 #include <boost/convert/printf.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15
16 using std::string;
17 using boost::convert;
18
19 namespace arg = boost::cnv::parameter;
20
21 int
22 main(int, char const* [])
23 {
24 boost::cnv::printf cnv;
25
26 string const not_int_str = "not an int";
27 string const std_str = "-11";
28 char const* const c_str = "-12";
29
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));
33
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());
37
38 string s01 = convert<string>(12.3456, cnv(arg::precision = 6)).value();
39 string s02 = convert<string>(12.3456, cnv(arg::precision = 3)).value();
40
41 BOOST_TEST(s01 == "12.345600");
42 BOOST_TEST(s02 == "12.346");
43
44 return boost::report_errors();
45 }
46
47 #endif