| 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 F, std::size_t... I> | ||
| 16 | 51 | KUMI_HIDDEN_ABI constexpr decltype(auto) generate_(kumi::_::adl_tag_t, F&& f, std::index_sequence<I...>) noexcept | |
| 17 | { | ||
| 18 | 204 | return kumi::tuple{kumi::invoke(KUMI_FWD(f), kumi::index<I>)...}; | |
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | template<std::size_t N> struct generate_t | ||
| 23 | { | ||
| 24 | template<typename Function> [[nodiscard]] KUMI_ABI constexpr auto operator()(Function const& f) const noexcept | ||
| 25 | { | ||
| 26 | 2 | if constexpr (N == 0) return kumi::tuple{}; | |
| 27 | 9 | else return generate_(kumi::_::adl_tag, f, std::make_index_sequence<N>{}); | |
| 28 | } | ||
| 29 | }; | ||
| 30 | |||
| 31 | template<std::size_t N> struct fill_t | ||
| 32 | { | ||
| 33 | template<typename T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T const& v) const noexcept | ||
| 34 | { | ||
| 35 | 2 | if constexpr (N == 0) return kumi::tuple{}; | |
| 36 | 75 | else return generate_(kumi::_::adl_tag, [&](auto) { return v; }, std::make_index_sequence<N>{}); | |
| 37 | } | ||
| 38 | }; | ||
| 39 | |||
| 40 | template<std::size_t N> struct iota_t | ||
| 41 | { | ||
| 42 | template<typename T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T v) const noexcept | ||
| 43 | { | ||
| 44 | 2 | if constexpr (N == 0) return kumi::tuple{}; | |
| 45 | else | ||
| 46 | 9 | return generate_( | |
| 47 | 81 | kumi::_::adl_tag, [&](auto I) { return static_cast<T>(v + I); }, std::make_index_sequence<N>{}); | |
| 48 | } | ||
| 49 | }; | ||
| 50 | |||
| 51 | //==================================================================================================================== | ||
| 52 | /** | ||
| 53 | @ingroup kumi_generators | ||
| 54 | |||
| 55 | @var generate | ||
| 56 | @brief Callable object creating a kumi::tuple containing `N` applications of the `f` Callable. | ||
| 57 | |||
| 58 | @qualifier nodiscard | ||
| 59 | @qualifier inline | ||
| 60 | @qualifier constexpr | ||
| 61 | @qualifier noexcept | ||
| 62 | |||
| 63 | @groupheader{Header file} | ||
| 64 | @code | ||
| 65 | #include <kumi/algorithm/generate.hpp> | ||
| 66 | @endcode | ||
| 67 | |||
| 68 | @groupheader{Call Signature} | ||
| 69 | |||
| 70 | @code | ||
| 71 | template<std::size_t, typename Function> | ||
| 72 | constexpr auto generate<N>(Function && f) noexcept; | ||
| 73 | @endcode | ||
| 74 | |||
| 75 | @subgroupheader{Template Parameters} | ||
| 76 | |||
| 77 | - `N`: Number of replications | ||
| 78 | |||
| 79 | @subgroupheader{Parameters} | ||
| 80 | |||
| 81 | - `f`: Callable object to apply | ||
| 82 | |||
| 83 | @subgroupheader{Return value} | ||
| 84 | |||
| 85 | - A tuple containing `N` applications of `f` | ||
| 86 | |||
| 87 | @groupheader{Helper type} | ||
| 88 | |||
| 89 | @snippet include/kumi/algorithm/generate.hpp generate_t | ||
| 90 | |||
| 91 | Computes the return type of a call to kumi::generate | ||
| 92 | |||
| 93 | @groupheader{Example} | ||
| 94 | |||
| 95 | @godbolt{doc/tuple/algo/generate.cpp} | ||
| 96 | |||
| 97 | **/ | ||
| 98 | //==================================================================================================================== | ||
| 99 | template<std::size_t N> inline constexpr generate_t<N> generate{}; | ||
| 100 | |||
| 101 | //==================================================================================================================== | ||
| 102 | /** | ||
| 103 | @ingroup kumi_generators | ||
| 104 | |||
| 105 | @var fill | ||
| 106 | @brief Callable object creating a kumi::tuple containing `N` copies of `v`. | ||
| 107 | |||
| 108 | @qualifier nodiscard | ||
| 109 | @qualifier inline | ||
| 110 | @qualifier constexpr | ||
| 111 | @qualifier noexcept | ||
| 112 | |||
| 113 | @groupheader{Header file} | ||
| 114 | @code | ||
| 115 | #include <kumi/algorithm/generate.hpp> | ||
| 116 | @endcode | ||
| 117 | |||
| 118 | @groupheader{Call Signature} | ||
| 119 | |||
| 120 | @code | ||
| 121 | template<std::size_t N, typename V> | ||
| 122 | constexpr auto fill<N>(V const& v) noexcept; | ||
| 123 | @endcode | ||
| 124 | |||
| 125 | @subgroupheader{Template Parameters} | ||
| 126 | |||
| 127 | - `N`: Number of replications | ||
| 128 | |||
| 129 | @subgroupheader{Parameters} | ||
| 130 | |||
| 131 | - `v`: Value to replicate | ||
| 132 | |||
| 133 | @subgroupheader{Return value} | ||
| 134 | |||
| 135 | - A tuple containing `N` copies of `v` | ||
| 136 | |||
| 137 | @groupheader{Helper type} | ||
| 138 | |||
| 139 | @snippet include/kumi/algorithm/generate.hpp fill_t | ||
| 140 | |||
| 141 | Computes the return type of a call to kumi::fill | ||
| 142 | |||
| 143 | @groupheader{Example} | ||
| 144 | |||
| 145 | @godbolt{doc/tuple/algo/fill.cpp} | ||
| 146 | |||
| 147 | **/ | ||
| 148 | //==================================================================================================================== | ||
| 149 | template<std::size_t N> inline constexpr fill_t<N> fill{}; | ||
| 150 | |||
| 151 | //==================================================================================================================== | ||
| 152 | /** | ||
| 153 | @ingroup kumi_generators | ||
| 154 | |||
| 155 | @var iota | ||
| 156 | @brief Callable object creating a kumi::tuple containing an increasing ramp of values. | ||
| 157 | |||
| 158 | @qualifier nodiscard | ||
| 159 | @qualifier inline | ||
| 160 | @qualifier constexpr | ||
| 161 | @qualifier noexcept | ||
| 162 | |||
| 163 | @groupheader{Header file} | ||
| 164 | @code | ||
| 165 | #include <kumi/algorithm/generate.hpp> | ||
| 166 | @endcode | ||
| 167 | |||
| 168 | @groupheader{Call Signature} | ||
| 169 | |||
| 170 | @code | ||
| 171 | template<std::size_t N, typename V> | ||
| 172 | constexpr auto iota<N>(V v) noexcept; | ||
| 173 | @endcode | ||
| 174 | |||
| 175 | @subgroupheader{Template Parameters} | ||
| 176 | |||
| 177 | - `N`: Number of replications | ||
| 178 | |||
| 179 | @subgroupheader{Parameters} | ||
| 180 | |||
| 181 | - `v`: Seed value | ||
| 182 | |||
| 183 | @subgroupheader{Return value} | ||
| 184 | |||
| 185 | - A tuple containing `N` copies of `{v, v + 1, ..., v + N-1}` | ||
| 186 | |||
| 187 | @groupheader{Helper type} | ||
| 188 | |||
| 189 | @snippet include/kumi/algorithm/generate.hpp iota_t | ||
| 190 | |||
| 191 | Computes the return type of a call to kumi::iota | ||
| 192 | |||
| 193 | @groupheader{Example} | ||
| 194 | |||
| 195 | @godbolt{doc/tuple/algo/iota.cpp} | ||
| 196 | |||
| 197 | **/ | ||
| 198 | //==================================================================================================================== | ||
| 199 | template<std::size_t N> inline constexpr iota_t<N> iota{}; | ||
| 200 | |||
| 201 | namespace result | ||
| 202 | { | ||
| 203 | //! [generate_t] | ||
| 204 | template<std::size_t N, typename Function> using generate_t = decltype(kumi::generate<N>(std::declval<Function>())); | ||
| 205 | |||
| 206 | template<std::size_t N, typename Function> struct generate | ||
| 207 | { | ||
| 208 | using type = kumi::result::generate_t<N, Function>; | ||
| 209 | }; | ||
| 210 | |||
| 211 | //! [generate_t] | ||
| 212 | |||
| 213 | //! [fill_t] | ||
| 214 | template<std::size_t N, typename T> using fill_t = decltype(kumi::fill<N>(std::declval<T>())); | ||
| 215 | |||
| 216 | template<std::size_t N, typename T> struct fill | ||
| 217 | { | ||
| 218 | using type = kumi::result::fill_t<N, T>; | ||
| 219 | }; | ||
| 220 | |||
| 221 | //! [fill_t] | ||
| 222 | |||
| 223 | //! [iota_t] | ||
| 224 | template<std::size_t N, typename T> using iota_t = decltype(kumi::iota<N>(std::declval<T>())); | ||
| 225 | |||
| 226 | template<std::size_t N, typename T> struct iota | ||
| 227 | { | ||
| 228 | using type = kumi::result::iota_t<N, T>; | ||
| 229 | }; | ||
| 230 | |||
| 231 | //! [iota_t] | ||
| 232 | } | ||
| 233 | } | ||
| 234 |