empty_storage.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/pair.hpp>
  5. #include <type_traits>
  6. namespace hana = boost::hana;
  7. struct empty1 { };
  8. struct empty2 { };
  9. struct empty3 { };
  10. struct empty4 { };
  11. // Make sure the storage of a pair is compressed
  12. static_assert(sizeof(hana::pair<empty1, int>) == sizeof(int), "");
  13. static_assert(sizeof(hana::pair<int, empty1>) == sizeof(int), "");
  14. // Also make sure that a pair with only empty members is empty too. This is
  15. // important to ensure, for example, that a tuple of pairs of empty objects
  16. // will get the EBO.
  17. static_assert(std::is_empty<hana::pair<empty1, empty2>>{}, "");
  18. // Make sure that a pair of empty pairs is still empty.
  19. static_assert(std::is_empty<
  20. hana::pair<hana::pair<empty1, empty2>, empty3>
  21. >{}, "");
  22. static_assert(std::is_empty<
  23. hana::pair<hana::pair<empty1, empty2>, hana::pair<empty3, empty4>>
  24. >{}, "");
  25. int main() { }