Skip to content

Commit 99b07a2

Browse files
committed
Improve compressed_tuple tests
1 parent d0be15d commit 99b07a2

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

interface/core/containers/compressed_tuple.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,19 @@ namespace hud
342342
} // namespace details::compressed_tuple
343343

344344
/**
345-
* tuples_t are objects that pack elements of possibly different types together in a single object, just like pair objects do for pairs of elements, but generalized for any number of elements.
346-
* Conceptually, they are similar to plain old data structures (C-like structs) but instead of having named data members, its elements are accessed by their order in the compressed_tuple.
347-
* The selection of particular elements within a compressed_tuple is done at the template-instantiation level, and thus, it must be specified at compile-time, with helper functions.
348-
* The compressed_tuple class is closely related to the pair class: tuples_t can be constructed from pairs, and pairs can be treated as tuples for certain purposes.
349-
* @tparam types_t... List of types of the compressed_tuple
345+
* compressed_tuple is an optimized variant of tuple that leverages the Empty Base Class Optimization (EBCO)
346+
* to reduce memory footprint when storing empty types (empty classes).
347+
*
348+
* Like tuple, compressed_tuple groups a heterogeneous set of objects into a single entity,
349+
* with element access performed at compile-time through helper functions. Its functionality
350+
* remains similar to tuple (element access, construction, pair compatibility, etc.),
351+
* but with a focus on memory compression.
352+
*
353+
* To maximize the effect of EBCO, it is recommended to place empty types first
354+
* in the template parameter list. If the same empty class type is used multiple times,
355+
* all of its occurrences should be placed at the beginning to ensure maximum compression.
356+
*
357+
* @tparam types_t... List of types stored in the compressed_tuple
350358
*/
351359
template<typename... types_t>
352360
class compressed_tuple

interface/core/containers/tuple.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,10 @@ namespace hud
636636
} // namespace details::tuple
637637

638638
/**
639-
* tuples_t are objects that pack elements of possibly different types together in a single object, just like pair objects do for pairs of elements, but generalized for any number of elements.
639+
* tuple are objects that pack elements of possibly different types together in a single object, just like pair objects do for pairs of elements, but generalized for any number of elements.
640640
* Conceptually, they are similar to plain old data structures (C-like structs) but instead of having named data members, its elements are accessed by their order in the tuple.
641641
* The selection of particular elements within a tuple is done at the template-instantiation level, and thus, it must be specified at compile-time, with helper functions.
642-
* The tuple class is closely related to the pair class: tuples_t can be constructed from pairs, and pairs can be treated as tuples for certain purposes.
642+
* The tuple class is closely related to the pair class: tuple can be constructed from pairs, and pairs can be treated as tuples for certain purposes.
643643
* @tparam types_t... List of types of the tuple
644644
*/
645645
template<typename... types_t>

test/compressed_tuple/compressed_tuple_misc.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
#include <core/containers/compressed_tuple.h>
22
#include <core/traits/is_same.h>
33

4-
namespace hud_test
4+
GTEST_TEST(compressed_tuple, sizeof_is_correct)
55
{
66
struct empty
77
{
88
};
9-
} // namespace hud_test
109

11-
GTEST_TEST(compressed_tuple, sizeof_is_correct)
12-
{
10+
struct empty_2
11+
{
12+
};
13+
14+
struct empty_3
15+
{
16+
};
17+
18+
struct non_empty
19+
{
20+
int x;
21+
};
22+
1323
hud_assert_eq(sizeof(hud::compressed_tuple<>), 1u);
14-
hud_assert_eq(sizeof(hud::compressed_tuple<hud_test::empty, hud_test::empty, hud_test::empty>), 3u);
15-
hud_assert_eq(sizeof(hud::compressed_tuple<i32, hud_test::empty, hud_test::empty>), 8u);
16-
hud_assert_eq(sizeof(hud::compressed_tuple<hud_test::empty, i32, hud_test::empty>), 8u);
17-
hud_assert_eq(sizeof(hud::compressed_tuple<hud_test::empty, hud_test::empty, i32>), 4u);
24+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty, empty>), 3u);
25+
hud_assert_eq(sizeof(hud::compressed_tuple<empty_2, empty, empty>), 2u);
26+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty_2, empty>), 2u);
27+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty, empty_2>), 2u);
28+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty_2, empty_3>), 1u);
29+
30+
hud_assert_eq(sizeof(hud::compressed_tuple<non_empty, empty, empty>), 8u);
31+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, non_empty, empty>), 8u);
32+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty, non_empty>), 4u);
33+
34+
hud_assert_eq(sizeof(hud::compressed_tuple<non_empty, empty, empty_2>), 4u);
35+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, non_empty, empty_2>), 4u);
36+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty_2, non_empty>), 4u);
37+
38+
hud_assert_eq(sizeof(hud::compressed_tuple<i32, empty, empty>), 8u);
39+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, i32, empty>), 8u);
40+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty, i32>), 4u);
41+
42+
hud_assert_eq(sizeof(hud::compressed_tuple<i32, empty, empty_2>), 4u);
43+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, i32, empty_2>), 4u);
44+
hud_assert_eq(sizeof(hud::compressed_tuple<empty, empty_2, i32>), 4u);
45+
1846
hud_assert_eq(sizeof(hud::compressed_tuple<i32>), 4u);
1947
hud_assert_eq(sizeof(hud::compressed_tuple<i32, i32>), 8u);
2048
hud_assert_eq(sizeof(hud::compressed_tuple<i32, i8, i32>), 12u);

0 commit comments

Comments
 (0)