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