GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/transpose.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 4 4 100.0%
Branches: 2 2 100.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 namespace _
14 {
15 template<typename T, std::size_t... I, std::size_t... J>
16 6 KUMI_HIDDEN_ABI constexpr decltype(auto) transpose_(kumi::_::adl_tag_t,
17 T&& t,
18 std::index_sequence<I...>,
19 std::index_sequence<J...> is)
20 {
21 12 return kumi::make_tuple(kumi::_::builder(KUMI_FWD(t), std::integral_constant<std::size_t, I>{}, is)...);
22 }
23 }
24
25 struct transpose_t
26 {
27 template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const
28 {
29 static_assert(kumi::_::supports_transpose<T>, "[KUMI] - Cannot transpose given product type");
30 3 if constexpr (kumi::concepts::empty_product_type<T>) return kumi::tuple{};
31 3 else if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t)));
32 else
33 {
34 6 constexpr std::size_t c = kumi::size_v<T>;
35 6 constexpr std::size_t s = kumi::size_v<kumi::element_t<0, T>>;
36 using outer = std::make_index_sequence<c>;
37 using inner = std::make_index_sequence<s>;
38
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 2 times.
6 return transpose_(kumi::_::adl_tag, KUMI_FWD(t), inner{}, outer{});
39 }
40 }
41 };
42
43 //====================================================================================================================
44 /**
45 @ingroup kumi_generators
46
47 @var transpose
48 @brief Callable object transposing a product type of product types by shifting elements in their
49 transposed position always returning a tuple as the external product type.
50
51 @note This function will issue a compile time error if each element of the input product type is not
52 itself a product type or if their sizes are not equal.
53
54 @qualifier nodiscard
55 @qualifier inline
56 @qualifier constexpr
57
58 @groupheader{Header file}
59 @code
60 #include <kumi/algorithm/transpose.hpp>
61 @endcode
62
63 @groupheader{Call Signature}
64
65 @code
66 template<product_type T>
67 constexpr auto transpose(T && t);
68 @endcode
69
70 @subgroupheader{Parameters}
71
72 - `t`: Product Type to transpose
73
74 @subgroupheader{Return value}
75
76 - A product type containing the transposed elements of `t`.
77
78 @groupheader{Helper type}
79
80 @snippet include/kumi/algorithm/transpose.hpp transpose_t
81
82 Computes the return type of a call to kumi::transpose
83
84 @groupheader{Examples}
85
86 @tab_begin
87
88 @tab{Tuple}
89 @godbolt{doc/tuple/algo/transpose.cpp}
90
91 @tab{Record}
92 @godbolt{doc/record/algo/transpose.cpp}
93
94 @tab_end
95 **/
96 //====================================================================================================================
97 KUMI_VARIABLE_ABI constexpr transpose_t transpose{};
98
99 namespace result
100 {
101 //! [transpose_t]
102 template<kumi::concepts::product_type T> using transpose_t = decltype(kumi::transpose(std::declval<T>()));
103
104 template<kumi::concepts::product_type T> struct transpose
105 {
106 using type = kumi::result::transpose_t<T>;
107 };
108
109 //! [transpose_t]
110 }
111 }
112