GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/detail/optimized.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 1608 1610 99.9%
Branches: 0 0 -%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 KUMI - Compact Tuple Tools
4 Copyright : KUMI Project Contributors
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 namespace kumi::_
11 {
12 //====================================================================================================================
13 // We optimize layout for tuple of size 1->10 and for homogeneous layout
14 // This shaves a bit of compile time and it makes symbol length of tuple NTTP shorter
15 //====================================================================================================================
16
17 // We usually don't want to optimize tuple of references
18 template<typename... Ts> inline constexpr bool no_references = (true && ... && !std::is_reference_v<Ts>);
19
20 // [[no_unique_address]] is too unstable at the moment, will go through the standard path
21 template<typename... Ts> inline constexpr bool no_empty = (true && ... && !std::is_empty_v<Ts>);
22
23 // We care about homogeneous tuple
24 template<typename T0, typename... Ts> inline constexpr bool all_the_same = (true && ... && std::is_same_v<T0, Ts>);
25
26 //====================================================================================================================
27 // Optimized binder for homogeneous layout if:
28 // - Size is greater than 1
29 // - All types are the same, non-reference and not empty
30 //====================================================================================================================
31 template<std::size_t... Is, typename T0, typename T1, typename... Ts>
32 requires(kumi::_::all_the_same<T0, T1, Ts...> && kumi::_::no_references<T0, T1, Ts...> &&
33 kumi::_::no_empty<T0, T1, Ts...>)
34 struct binder<std::index_sequence<Is...>, T0, T1, Ts...>
35 {
36 using type = T0;
37 static constexpr std::size_t N = 2 + sizeof...(Ts);
38
39 static constexpr bool is_homogeneous = true;
40 type members[N];
41
42 template<std::size_t I>
43 680 KUMI_HIDDEN_ABI constexpr auto& operator()(std::integral_constant<std::size_t, I>) & noexcept
44 {
45 680 return members[I];
46 }
47
48 template<std::size_t I>
49 222742 KUMI_HIDDEN_ABI constexpr auto const& operator()(std::integral_constant<std::size_t, I>) const& noexcept
50 {
51 222742 return members[I];
52 }
53
54 template<std::size_t I>
55 444 KUMI_HIDDEN_ABI constexpr auto&& operator()(std::integral_constant<std::size_t, I>) && noexcept
56 {
57 444 return static_cast<type&&>(members[I]);
58 }
59
60 template<std::size_t I>
61 KUMI_HIDDEN_ABI constexpr auto const&& operator()(std::integral_constant<std::size_t, I>) const&& noexcept
62 {
63 return static_cast<type const&&>(members[I]);
64 }
65 };
66
67 //====================================================================================================================
68 // Optimized binder for 1->10 elements, none being reference (Helps with symbol length of NTTPs)
69 //====================================================================================================================
70 623375 FOR_LIST_OF_STRUCTS(KUMI_BINDER)
71 }
72