GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/algorithm/rotate.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 0 0 -%
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 template<std::size_t R> struct rotate_left_t
13 {
14 template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const noexcept
15 {
16 if constexpr (kumi::concepts::empty_product_type<T>) return KUMI_FWD(t);
17 4 else if constexpr ((R % kumi::size_v<T>) == 0) return KUMI_FWD(t);
18 else
19 10 return kumi::_::builder(KUMI_FWD(t),
20 10 kumi::function::rotate_index_sequence<R % kumi::size_v<T>, kumi::size_v<T>>{});
21 }
22 };
23
24 template<std::size_t R> struct rotate_right_t
25 {
26 template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const
27 {
28 if constexpr (kumi::concepts::empty_product_type<T>) return KUMI_FWD(t);
29 4 else if constexpr ((R % kumi::size_v<T>) == 0) return KUMI_FWD(t);
30 else
31 10 return kumi::_::builder(
32 KUMI_FWD(t),
33 10 kumi::function::rotate_index_sequence<(kumi::size_v<T> - (R % kumi::size_v<T>)), kumi::size_v<T>>{});
34 }
35 };
36
37 //====================================================================================================================
38 /**
39 @ingroup kumi_generators
40
41 @var rotate_left
42 @brief Callable object
43
44 On record types, this function operates on elements as if they were ordered. The considered order is the order
45 of declaration.
46
47 @qualifier nodiscard
48 @qualifier inline
49 @qualifier constexpr
50
51 @groupheader{Header file}
52 @code
53 #include <kumi/algorithm/rotate.hpp>
54 @endcode
55
56 @groupheader{Call Signature}
57
58 @code
59 template<std::size_t R, product_type T>
60 constexpr auto rotate_left<R>(T && t) ;
61 @endcode
62
63 @subgroupheader{Template Parameters}
64 - `R`: Rotation factor
65
66 @subgroupheader{Parameters}
67
68 - `t`: Product Type to rotate
69
70 @subgroupheader{Return value}
71
72 - A product type equivalent to `t` with elements rotated R positions to the left.
73
74 @groupheader{Helper type}
75
76 @snippet include/kumi/algorithm/rotate.hpp rotate_left_t
77
78 Computes the return type of a call to kumi::rotate_left
79
80 @groupheader{Examples}
81
82 @tab_begin
83
84 @tab{Tuple}
85 @godbolt{doc/tuple/algo/rotate_left.cpp}
86
87 @tab{Record}
88 @godbolt{doc/record/algo/rotate_left.cpp}
89
90 @tab_end
91 **/
92 //====================================================================================================================
93 template<std::size_t R> inline constexpr rotate_left_t<R> rotate_left{};
94
95 //====================================================================================================================
96 /**
97 @ingroup kumi_generators
98
99 @var rotate_right
100 @brief Callable object
101
102 On record types, this function operates on elements as if they were ordered. The considered order is the order
103 of declaration.
104
105 @qualifier nodiscard
106 @qualifier inline
107 @qualifier constexpr
108
109 @groupheader{Header file}
110 @code
111 #include <kumi/algorithm/rotate.hpp>
112 @endcode
113
114 @groupheader{Call Signature}
115
116 @code
117 template<std::size_t R, product_type T>
118 constexpr auto rotate_right<R>(T && t) ;
119 @endcode
120
121 @subgroupheader{Template Parameters}
122 - `R`: Rotation factor
123
124 @subgroupheader{Parameters}
125
126 - `t`: Product Type to rotate
127
128 @subgroupheader{Return value}
129
130 - A product type equivalent to `t` with elements rotated R positions to the right.
131
132 @groupheader{Helper type}
133
134 @snippet include/kumi/algorithm/rotate.hpp rotate_right_t
135
136 Computes the return type of a call to kumi::rotate_right
137
138 @groupheader{Examples}
139
140 @tab_begin
141
142 @tab{Tuple}
143 @godbolt{doc/tuple/algo/rotate_right.cpp}
144
145 @tab{Record}
146 @godbolt{doc/record/algo/rotate_right.cpp}
147
148 @tab_end
149 **/
150 //====================================================================================================================
151 template<std::size_t R> inline constexpr rotate_right_t<R> rotate_right{};
152
153 namespace result
154 {
155 //! [rotate_left_t]
156 template<std::size_t R, kumi::concepts::product_type T>
157 using rotate_left_t = decltype(kumi::rotate_left<R>(std::declval<T>()));
158
159 template<std::size_t R, kumi::concepts::product_type T> struct rotate_left
160 {
161 using type = kumi::result::rotate_left_t<R, T>;
162 };
163
164 //! [rotate_left_t]
165
166 //! [rotate_right_t]
167 template<std::size_t R, kumi::concepts::product_type T>
168 using rotate_right_t = decltype(kumi::rotate_right<R>(std::declval<T>()));
169
170 template<std::size_t R, kumi::concepts::product_type T> struct rotate_right
171 {
172 using type = kumi::result::rotate_right_t<R, T>;
173 };
174
175 //! [rotate_right_t]
176 }
177 }
178