]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/test/fallbacks.cpp
b0192e9b1ce4ce8cfdb70546836b97493197258c
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/stream.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15 #include <boost/function.hpp>
16 #include <boost/bind.hpp>
18 namespace { namespace local
20 bool called_functor_int
;
21 bool called_functor_double
;
22 bool called_functor_foo
;
23 bool called_function_int
;
24 bool called_function_long
;
27 struct functor_int
{ int operator() () const { local:: called_functor_int
= true; return INT_MAX
; }};
28 struct functor_double
{ double operator() () const { local::called_functor_double
= true; return INT_MAX
; }};
29 struct functor_foo
{ int func (int) const { local:: called_functor_foo
= true; return INT_MAX
; }};
31 int function_int () { local:: called_function_int
= true; return INT_MAX
; }
32 long function_long () { local::called_function_long
= true; return INT_MAX
; }
35 main(int, char const* [])
37 boost::cnv::cstream cnv
;
40 int i01
= boost::convert
<int>("uhm", cnv
).value_or_eval(functor_int());
41 int i02
= boost::convert
<int>("uhm", cnv
).value_or_eval(functor_double());
42 int i03
= boost::convert
<int>("uhm", cnv
).value_or_eval(boost::bind(&functor_foo::func
, foo
, 0));
43 int i04
= boost::convert
<int>("uhm", cnv
).value_or_eval(function_int
);
44 int i05
= boost::convert
<int>("uhm", cnv
).value_or_eval(function_long
);
46 BOOST_TEST(local:: called_functor_int
&& i01
== INT_MAX
);
47 BOOST_TEST(local::called_functor_double
&& i02
== INT_MAX
);
48 BOOST_TEST(local:: called_functor_foo
&& i03
== INT_MAX
);
49 BOOST_TEST(local:: called_function_int
&& i04
== INT_MAX
);
50 BOOST_TEST(local:: called_function_long
&& i05
== INT_MAX
);
52 local:: called_functor_int
= false;
53 local::called_functor_double
= false;
54 local:: called_functor_foo
= false;
55 local:: called_function_int
= false;
56 local:: called_function_long
= false;
58 boost::convert
<int>("uhm", cnv
, functor_int());
59 boost::convert
<int>("uhm", cnv
, functor_double());
60 boost::convert
<int>("uhm", cnv
, boost::bind(&functor_foo::func
, foo
, 0));
61 boost::convert
<int>("uhm", cnv
, function_int
);
62 boost::convert
<int>("uhm", cnv
, function_long
);
64 BOOST_TEST(local:: called_functor_int
&& i01
== INT_MAX
);
65 BOOST_TEST(local::called_functor_double
&& i02
== INT_MAX
);
66 BOOST_TEST(local:: called_functor_foo
&& i03
== INT_MAX
);
67 BOOST_TEST(local:: called_function_int
&& i04
== INT_MAX
);
68 BOOST_TEST(local:: called_function_long
&& i05
== INT_MAX
);
72 boost::convert
<int>("uhm", cnv
, boost::throw_on_failure
);
75 catch (boost::bad_optional_access
const&)
78 return boost::report_errors();