| 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 | namespace _ | ||
| 13 | { | ||
| 14 | template<std::size_t N, std::size_t O, std::size_t Sz, typename T, std::size_t... I> | ||
| 15 | 70 | KUMI_HIDDEN_ABI constexpr auto tiles_(kumi::_::adl_tag_t, T&& t, std::index_sequence<I...>) | |
| 16 | { | ||
| 17 | 70 | return kumi::tuple{kumi::_::builder( | |
| 18 | 70 | KUMI_FWD(t), kumi::function::slice_index_sequence<I * O, (I * O + N < Sz) ? (I * O + N) : Sz>{})...}; | |
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | template<std::size_t N, std::size_t O> struct tiles_t | ||
| 23 | { | ||
| 24 | template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const | ||
| 25 | { | ||
| 26 | static_assert(N > 0 && N <= kumi::size_v<T>, "[KUMI] - Invalid tile size"); | ||
| 27 | |||
| 28 | if constexpr (N == kumi::size_v<T>) return kumi::make_tuple(t); | ||
| 29 | else | ||
| 30 | { | ||
| 31 | constexpr auto range = std::make_index_sequence<1 + (kumi::size_v<T> - N + O - 1) / O>{}; | ||
| 32 | 70 | return kumi::_::tiles_<N, O, kumi::size_v<T>>(kumi::_::adl_tag, KUMI_FWD(t), range); | |
| 33 | } | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | //==================================================================================================================== | ||
| 38 | /** | ||
| 39 | @ingroup kumi_generators | ||
| 40 | |||
| 41 | @var tiles | ||
| 42 | @brief Callable object creating a tuple of product types, each containing `N` consecutive elements from `t`. | ||
| 43 | Tiles starts at 0 and advance by `O` element each time. | ||
| 44 | |||
| 45 | On record types, this function operates on elements as if they were ordered. The considered order is the order | ||
| 46 | of declaration. | ||
| 47 | |||
| 48 | @note Tiles is the most general form of tiling each inner product_type is a tile over `t` | ||
| 49 | starting at index `tile_size * tile_number`. The last tile will be smaller if the | ||
| 50 | size of the product type is not a multiple of the tile size. | ||
| 51 | |||
| 52 | @qualifier nodiscard | ||
| 53 | @qualifier inline | ||
| 54 | @qualifier constexpr | ||
| 55 | |||
| 56 | @groupheader{Header file} | ||
| 57 | @code | ||
| 58 | #include <kumi/algorithm/tiler.hpp> | ||
| 59 | @endcode | ||
| 60 | |||
| 61 | @groupheader{Call Signature} | ||
| 62 | |||
| 63 | @code | ||
| 64 | template<std::size_t N, std::size_t O, product_type T> | ||
| 65 | constexpr auto tiles<N,O>(T && t); | ||
| 66 | @endcode | ||
| 67 | |||
| 68 | @subgroupheader{Template Parameters} | ||
| 69 | |||
| 70 | - `N`: Size of the tile to generate | ||
| 71 | - `O`: Offset from the beginning of the previous tile | ||
| 72 | |||
| 73 | @subgroupheader{Parameters} | ||
| 74 | |||
| 75 | - `t`: Product Type from which to extract the tiles | ||
| 76 | |||
| 77 | @subgroupheader{Return value} | ||
| 78 | |||
| 79 | - A tuple of product types, each containing `N` consecutive elements of `t` offset by O | ||
| 80 | |||
| 81 | @groupheader{Helper type} | ||
| 82 | |||
| 83 | @snippet include/kumi/algorithm/tiler.hpp tiles_t | ||
| 84 | |||
| 85 | Computes the return type of a call to kumi::tiles | ||
| 86 | |||
| 87 | @groupheader{Examples} | ||
| 88 | |||
| 89 | @tab_begin | ||
| 90 | |||
| 91 | @tab{Tuple} | ||
| 92 | @godbolt{doc/tuple/algo/tiles.cpp} | ||
| 93 | |||
| 94 | @tab{Record} | ||
| 95 | @godbolt{doc/record/algo/tiles.cpp} | ||
| 96 | |||
| 97 | @tab_end | ||
| 98 | **/ | ||
| 99 | //==================================================================================================================== | ||
| 100 | template<std::size_t N, std::size_t O> inline constexpr tiles_t<N, O> tiles{}; | ||
| 101 | |||
| 102 | //==================================================================================================================== | ||
| 103 | /** | ||
| 104 | @ingroup kumi_generators | ||
| 105 | |||
| 106 | @var windows | ||
| 107 | @brief Callable object creating a tuple of product types, each containing `N` consecutive elements from `t`. | ||
| 108 | Windows starts at 0 and advance by `1` element each time. | ||
| 109 | |||
| 110 | On record types, this function operates on elements as if they were ordered. The considered order is the order | ||
| 111 | of declaration. | ||
| 112 | |||
| 113 | @note Windows behaves like overlapping tiles: each inner product_type is a tile over `t` | ||
| 114 | starting at index `tile_number`. All the windows are of the same size. | ||
| 115 | |||
| 116 | @qualifier nodiscard | ||
| 117 | @qualifier inline | ||
| 118 | @qualifier constexpr | ||
| 119 | |||
| 120 | @groupheader{Header file} | ||
| 121 | @code | ||
| 122 | #include <kumi/algorithm/tiler.hpp> | ||
| 123 | @endcode | ||
| 124 | |||
| 125 | @groupheader{Call Signature} | ||
| 126 | |||
| 127 | @code | ||
| 128 | template<std::size_t N, product_type T> | ||
| 129 | constexpr auto windows<N>(T && t); | ||
| 130 | @endcode | ||
| 131 | |||
| 132 | @subgroupheader{Template Parameters} | ||
| 133 | |||
| 134 | - `N`: Size of the window to generate | ||
| 135 | |||
| 136 | @subgroupheader{Parameters} | ||
| 137 | |||
| 138 | - `t`: Product Type from which to extract the windows | ||
| 139 | |||
| 140 | @subgroupheader{Return value} | ||
| 141 | |||
| 142 | - A tuple of product types, each containing `N` consecutive elements of `t` | ||
| 143 | |||
| 144 | @groupheader{Helper type} | ||
| 145 | |||
| 146 | @snippet include/kumi/algorithm/tiler.hpp windows_t | ||
| 147 | |||
| 148 | Computes the return type of a call to kumi::windows | ||
| 149 | |||
| 150 | @groupheader{Examples} | ||
| 151 | |||
| 152 | @tab_begin | ||
| 153 | |||
| 154 | @tab{Tuple} | ||
| 155 | @godbolt{doc/tuple/algo/windows.cpp} | ||
| 156 | |||
| 157 | @tab{Record} | ||
| 158 | @godbolt{doc/record/algo/windows.cpp} | ||
| 159 | |||
| 160 | @tab_end | ||
| 161 | **/ | ||
| 162 | //==================================================================================================================== | ||
| 163 | template<std::size_t N> inline constexpr tiles_t<N, 1> windows{}; | ||
| 164 | |||
| 165 | //==================================================================================================================== | ||
| 166 | /** | ||
| 167 | @ingroup kumi_generators | ||
| 168 | |||
| 169 | @var chunks | ||
| 170 | @brief Callable object creating a tuple of product types, each containing `N` consecutive elements from `t`. | ||
| 171 | Chunks starts at 0 and advance by `N` element each time. | ||
| 172 | |||
| 173 | On record types, this function operates on elements as if they were ordered. The considered order is the order | ||
| 174 | of declaration. | ||
| 175 | |||
| 176 | @note Chunks behaves like paving tiles: each inner product_type is a tile over `t` | ||
| 177 | starting at index `chunk_size * chunk_number`. The last chunk will be smaller if the | ||
| 178 | size of the product_type is not a multiple of the chunk size. | ||
| 179 | |||
| 180 | @qualifier nodiscard | ||
| 181 | @qualifier inline | ||
| 182 | @qualifier constexpr | ||
| 183 | |||
| 184 | @groupheader{Header file} | ||
| 185 | @code | ||
| 186 | #include <kumi/algorithm/tiler.hpp> | ||
| 187 | @endcode | ||
| 188 | |||
| 189 | @groupheader{Call Signature} | ||
| 190 | |||
| 191 | @code | ||
| 192 | template<std::size_t N, product_type T> | ||
| 193 | constexpr auto windows<N>(T && t); | ||
| 194 | @endcode | ||
| 195 | |||
| 196 | @subgroupheader{Template Parameters} | ||
| 197 | |||
| 198 | - `N`: Size of the chunks to generate | ||
| 199 | |||
| 200 | @subgroupheader{Parameters} | ||
| 201 | |||
| 202 | - `t`: Product Type from which to extract the chunks | ||
| 203 | |||
| 204 | @subgroupheader{Return value} | ||
| 205 | |||
| 206 | - A tuple of product types, each containing `N` consecutive elements of `t` | ||
| 207 | |||
| 208 | @groupheader{Helper type} | ||
| 209 | |||
| 210 | @snippet include/kumi/algorithm/tiler.hpp chunks_t | ||
| 211 | |||
| 212 | Computes the return type of a call to kumi::chunks | ||
| 213 | |||
| 214 | @groupheader{Examples} | ||
| 215 | |||
| 216 | @tab_begin | ||
| 217 | |||
| 218 | @tab{Tuple} | ||
| 219 | @godbolt{doc/tuple/algo/chunks.cpp} | ||
| 220 | |||
| 221 | @tab{Record} | ||
| 222 | @godbolt{doc/record/algo/chunks.cpp} | ||
| 223 | |||
| 224 | @tab_end | ||
| 225 | **/ | ||
| 226 | //==================================================================================================================== | ||
| 227 | template<std::size_t N> inline constexpr tiles_t<N, N> chunks{}; | ||
| 228 | |||
| 229 | namespace result | ||
| 230 | { | ||
| 231 | //! [tiles_t] | ||
| 232 | template<std::size_t N, std::size_t O, kumi::concepts::product_type T> | ||
| 233 | using tiles_t = decltype(kumi::tiles<N, O>(std::declval<T>())); | ||
| 234 | |||
| 235 | template<std::size_t N, std::size_t O, kumi::concepts::product_type T> struct tiles | ||
| 236 | { | ||
| 237 | using type = kumi::result::tiles_t<N, O, T>; | ||
| 238 | }; | ||
| 239 | |||
| 240 | //! [tiles_t] | ||
| 241 | |||
| 242 | //! [windows_t] | ||
| 243 | template<std::size_t N, kumi::concepts::product_type T> | ||
| 244 | using windows_t = decltype(kumi::windows<N>(std::declval<T>())); | ||
| 245 | |||
| 246 | template<std::size_t N, kumi::concepts::product_type T> struct windows | ||
| 247 | { | ||
| 248 | using type = kumi::result::windows_t<N, T>; | ||
| 249 | }; | ||
| 250 | |||
| 251 | //! [windows_t] | ||
| 252 | |||
| 253 | //! [chunks_t] | ||
| 254 | template<std::size_t N, kumi::concepts::product_type T> | ||
| 255 | using chunks_t = decltype(kumi::chunks<N>(std::declval<T>())); | ||
| 256 | |||
| 257 | template<std::size_t N, kumi::concepts::product_type T> struct chunks | ||
| 258 | { | ||
| 259 | using type = kumi::result::chunks_t<N, T>; | ||
| 260 | }; | ||
| 261 | |||
| 262 | //! [chunks_t] | ||
| 263 | } | ||
| 264 | } | ||
| 265 |