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)
main(int,char const * [])9 int main(int, char const* []) { return 0; }
10 #else
11
12 #include <boost/convert.hpp>
13 #include <boost/convert/detail/is_converter.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15
16 using std::string;
17 using std::wstring;
18
19 namespace { namespace local
20 {
21 typedef void not_converter01 (string const&);
22 typedef void not_converter02 (int const&, string const&);
23 typedef void not_converter03 ();
24 typedef void converter01 (int const&, boost::optional<string>&);
25 typedef void converter02 (double const&, boost::optional<string>&);
26
27 struct converter11
28 {
operator ()__anondc7200f40111::local::converter1129 void operator()(int const&, boost::optional<string>&) {}
operator ()__anondc7200f40111::local::converter1130 void operator()(double const&, boost::optional<string>&) {}
operator ()__anondc7200f40111::local::converter1131 void operator()(string const&, boost::optional<int>&) {}
32 };
33 struct converter12
34 {
operator ()__anondc7200f40111::local::converter1235 template<typename TypeIn, typename TypeOut> void operator()(TypeIn const&, boost::optional<TypeOut>&) {}
36 };
37 struct converter13
38 {
operator ()__anondc7200f40111::local::converter1339 void operator()(int const&, boost::optional<string>&) {}
40 };
41 struct converter14
42 {
operator ()__anondc7200f40111::local::converter1443 void operator()(int const&, boost::optional<string>&) const {}
44 };
45 struct not_converter11
46 {
47 };
48 struct not_converter12
49 {
operator ()__anondc7200f40111::local::not_converter1250 void operator()() {}
51 };
52 struct not_converter13
53 {
operator ()__anondc7200f40111::local::not_converter1354 void operator()(int const&, string const&) {}
55 };
56 }}
57
58 int
main(int,char const * [])59 main(int, char const* [])
60 {
61 BOOST_TEST( (boost::cnv::is_cnv<local::converter01, int, string>::value));
62 BOOST_TEST( (boost::cnv::is_cnv<local::converter01, double, string>::value));
63 BOOST_TEST( (boost::cnv::is_cnv<local::converter01, short int, string>::value));
64 BOOST_TEST( (boost::cnv::is_cnv<local::converter11, int, string>::value));
65 BOOST_TEST( (boost::cnv::is_cnv<local::converter11, double, string>::value));
66 BOOST_TEST( (boost::cnv::is_cnv<local::converter11, string, int>::value));
67 BOOST_TEST( (boost::cnv::is_cnv<local::converter12, int, string>::value));
68 BOOST_TEST( (boost::cnv::is_cnv<local::converter12, double, string>::value));
69 BOOST_TEST( (boost::cnv::is_cnv<local::converter12, string, int>::value));
70 BOOST_TEST( (boost::cnv::is_cnv<local::converter13, int, string>::value));
71 BOOST_TEST( (boost::cnv::is_cnv<local::converter13, double, string>::value));
72 BOOST_TEST( (boost::cnv::is_cnv<local::converter13, int, string>::value));
73 BOOST_TEST( (boost::cnv::is_cnv<local::converter14, int, string>::value));
74 BOOST_TEST(!(boost::cnv::is_cnv<local::converter13, string, int>::value));
75 BOOST_TEST(!(boost::cnv::is_cnv<local::converter14, string, int>::value));
76
77 BOOST_TEST(!(boost::cnv::is_cnv<local::not_converter01, int, string>::value));
78 BOOST_TEST(!(boost::cnv::is_cnv<local::not_converter02, int, string>::value));
79 BOOST_TEST(!(boost::cnv::is_cnv<local::not_converter11, int, string>::value));
80 BOOST_TEST(!(boost::cnv::is_cnv<local::not_converter12, int, string>::value));
81 BOOST_TEST(!(boost::cnv::is_cnv<local::not_converter13, int, string>::value));
82
83 return boost::report_errors();
84 }
85
86 #endif
87