1// Copyright Louis Dionne 2013-2022
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
5#include <boost/hana/pair.hpp>
6
7#include <type_traits>
8namespace hana = boost::hana;
9
10
11struct empty1 { };
12struct empty2 { };
13struct empty3 { };
14struct empty4 { };
15
16// Make sure the storage of a pair is compressed
17static_assert(sizeof(hana::pair<empty1, int>) == sizeof(int), "");
18static_assert(sizeof(hana::pair<int, empty1>) == sizeof(int), "");
19
20// Also make sure that a pair with only empty members is empty too. This is
21// important to ensure, for example, that a tuple of pairs of empty objects
22// will get the EBO.
23static_assert(std::is_empty<hana::pair<empty1, empty2>>{}, "");
24
25// Make sure that a pair of empty pairs is still empty.
26static_assert(std::is_empty<
27 hana::pair<hana::pair<empty1, empty2>, empty3>
28>{}, "");
29
30static_assert(std::is_empty<
31 hana::pair<hana::pair<empty1, empty2>, hana::pair<empty3, empty4>>
32>{}, "");
33
34int main() { }
35

source code of boost/libs/hana/test/pair/empty_storage.cpp