empty_value_final_test.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Copyright 2018 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/core/empty_value.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. #if !defined(BOOST_NO_CXX11_FINAL)
  10. class type final {
  11. public:
  12. explicit type(int count)
  13. : value_(count) { }
  14. int value() const {
  15. return value_ + 1;
  16. }
  17. int value() {
  18. return value_ + 2;
  19. }
  20. private:
  21. int value_;
  22. };
  23. struct empty final {
  24. int value() const {
  25. return 1;
  26. }
  27. int value() {
  28. return 2;
  29. }
  30. };
  31. void test_type()
  32. {
  33. const boost::empty_value<type> v1(boost::empty_init_t(), 3);
  34. BOOST_TEST(v1.get().value() == 4);
  35. boost::empty_value<type> v2(boost::empty_init_t(), 3);
  36. BOOST_TEST(v2.get().value() == 5);
  37. }
  38. void test_empty()
  39. {
  40. const boost::empty_value<empty> v1 = boost::empty_init_t();
  41. BOOST_TEST(v1.get().value() == 1);
  42. boost::empty_value<empty> v2;
  43. BOOST_TEST(v2.get().value() == 2);
  44. }
  45. int main()
  46. {
  47. test_type();
  48. test_empty();
  49. return boost::report_errors();
  50. }
  51. #else
  52. int main()
  53. {
  54. return 0;
  55. }
  56. #endif