has_member.cpp 3.3 KB

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