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 * [])9int 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; }; begin__anon62be00340211::local::test0228 struct test02 { char* begin() { return 0; } }; operator ()__anon62be00340211::local::test2229 struct test22 { void operator()() {} }; 30 }} 31 //] 32 33 namespace { namespace local 34 { 35 struct test03 36 { begin__anon62be00340311::local::test0337 void begin(int) {} begin__anon62be00340311::local::test0338 int begin(int, int) { return 0; } 39 }; 40 struct test04 41 { ~test04__anon62be00340311::local::test0442 virtual ~test04() {} 43 begin__anon62be00340311::local::test0444 private: virtual char* begin() { return 0; } 45 }; 46 struct test05 47 { begin__anon62be00340311::local::test0548 virtual char* begin() { return 0; } ~test05__anon62be00340311::local::test0549 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; }; no_begin__anon62be00340311::local::test1257 struct test12 { char* no_begin() { return 0; } }; 58 }} 59 60 namespace { namespace local 61 { zoo__anon62be00340411::local::test2162 struct test21 { void zoo () {} }; operator ()__anon62be00340411::local::test2363 struct test23 { void operator() () const {} }; operator ()__anon62be00340411::local::test2464 struct test24 { int operator() (int) { return 0; } }; operator ()__anon62be00340411::local::test2565 struct test25 { int operator() (int) const { return 0; } }; operator ()__anon62be00340411::local::test2666 struct test26 { int operator() (int) const { return 0; } void operator() () const {} }; 67 }} 68 69 int main(int,char const * [])70main(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 105