]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
b32b8144 | 8 | #if defined(BOOST_CONVERT_IS_NOT_SUPPORTED) |
7c673cae FG |
9 | int main(int, char const* []) { return 0; } |
10 | #else | |
11 | ||
12 | #include <boost/convert.hpp> | |
13 | #include <boost/detail/lightweight_test.hpp> | |
14 | #include <vector> | |
15 | #include <iostream> | |
16 | ||
17 | //[has_member_declaration | |
18 | namespace { namespace local | |
19 | { | |
20 | BOOST_DECLARE_HAS_MEMBER(has_begin, begin); | |
21 | BOOST_DECLARE_HAS_MEMBER(has_funop, operator()); | |
22 | }} | |
23 | //] | |
24 | //[has_member_classes_tested | |
25 | namespace { namespace local | |
26 | { | |
27 | struct test01 { int begin; }; | |
28 | struct test02 { char* begin() { return 0; } }; | |
29 | struct test22 { void operator()() {} }; | |
30 | }} | |
31 | //] | |
32 | ||
33 | namespace { namespace local | |
34 | { | |
35 | struct test03 | |
36 | { | |
37 | void begin(int) {} | |
38 | int begin(int, int) { return 0; } | |
39 | }; | |
40 | struct test04 | |
41 | { | |
42 | virtual ~test04() {} | |
43 | ||
44 | private: virtual char* begin() { return 0; } | |
45 | }; | |
46 | struct test05 | |
47 | { | |
48 | virtual char* begin() { return 0; } | |
49 | virtual ~test05() {} | |
50 | }; | |
51 | struct test06 : public test04 {}; | |
52 | struct test07 : private test04 {}; | |
53 | struct test08 : public test05 {}; | |
54 | struct test09 : private test05 {}; | |
55 | ||
56 | struct test11 { int no_begin; }; | |
57 | struct test12 { char* no_begin() { return 0; } }; | |
58 | }} | |
59 | ||
60 | namespace { namespace local | |
61 | { | |
62 | struct test21 { void zoo () {} }; | |
63 | struct test23 { void operator() () const {} }; | |
64 | struct test24 { int operator() (int) { return 0; } }; | |
65 | struct test25 { int operator() (int) const { return 0; } }; | |
66 | struct test26 { int operator() (int) const { return 0; } void operator() () const {} }; | |
67 | }} | |
68 | ||
69 | int | |
70 | main(int, char const* []) | |
71 | { | |
72 | BOOST_TEST(local::has_begin<local::test01>::value == true); | |
73 | BOOST_TEST(local::has_begin<local::test02>::value == true); | |
74 | BOOST_TEST(local::has_begin<local::test03>::value == true); | |
75 | BOOST_TEST(local::has_begin<local::test04>::value == true); | |
76 | BOOST_TEST(local::has_begin<local::test05>::value == true); | |
77 | BOOST_TEST(local::has_begin<local::test06>::value == true); | |
78 | BOOST_TEST(local::has_begin<local::test07>::value == true); | |
79 | BOOST_TEST(local::has_begin<local::test08>::value == true); | |
80 | BOOST_TEST(local::has_begin<local::test09>::value == true); | |
81 | BOOST_TEST(local::has_begin<std::string>::value == true); | |
82 | BOOST_TEST(local::has_begin<std::vector<int> >::value == true); | |
83 | ||
84 | BOOST_TEST(local::has_begin<local::test11>::value == false); | |
85 | BOOST_TEST(local::has_begin<local::test12>::value == false); | |
86 | BOOST_TEST(local::has_begin<std::iostream>::value == false); | |
87 | ||
88 | //[has_member_usage | |
89 | BOOST_TEST(local::has_begin<local::test01>::value == true); | |
90 | BOOST_TEST(local::has_begin<local::test02>::value == true); | |
91 | BOOST_TEST(local::has_funop<local::test22>::value == true); | |
92 | //] | |
93 | ||
94 | BOOST_TEST(local::has_funop<local::test21>::value == false); | |
95 | BOOST_TEST(local::has_funop<local::test22>::value == true); | |
96 | BOOST_TEST(local::has_funop<local::test23>::value == true); | |
97 | BOOST_TEST(local::has_funop<local::test24>::value == true); | |
98 | BOOST_TEST(local::has_funop<local::test25>::value == true); | |
99 | BOOST_TEST(local::has_funop<local::test26>::value == true); | |
100 | ||
101 | return boost::report_errors(); | |
102 | } | |
103 | ||
104 | #endif |