empty_value_size_test.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/config.hpp>
  8. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  9. #include <boost/core/empty_value.hpp>
  10. #include <boost/core/lightweight_test.hpp>
  11. struct T1 { };
  12. struct S1
  13. : boost::empty_value<T1, 0, true> { };
  14. struct T2 {
  15. int value;
  16. };
  17. struct S2
  18. : boost::empty_value<T1, 0, true>
  19. , boost::empty_value<T2, 1, true> { };
  20. struct S3
  21. : boost::empty_value<T1, 0, false>
  22. , boost::empty_value<T2, 1, true> { };
  23. struct T3 { };
  24. struct S4
  25. : boost::empty_value<T1, 0, true>
  26. , boost::empty_value<T3, 1, true> { };
  27. struct S5
  28. : boost::empty_value<T1, 0, false>
  29. , boost::empty_value<T3, 1, false> { };
  30. struct S6
  31. : boost::empty_value<T1, 0, true>
  32. , boost::empty_value<T2, 1, true>
  33. , boost::empty_value<T3, 2, true> { };
  34. int main()
  35. {
  36. BOOST_TEST(sizeof(S1) == sizeof(T1));
  37. BOOST_TEST(sizeof(S2) == sizeof(T2));
  38. BOOST_TEST(sizeof(S3) > sizeof(T2));
  39. BOOST_TEST(sizeof(S4) == sizeof(T1));
  40. BOOST_TEST(sizeof(S5) > sizeof(T1));
  41. BOOST_TEST(sizeof(S6) == sizeof(T2));
  42. return boost::report_errors();
  43. }
  44. #else
  45. int main()
  46. {
  47. return 0;
  48. }
  49. #endif