diff options
| author | Maxime Coste <mawww@kakoune.org> | 2025-06-27 17:50:25 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2025-06-27 17:50:25 +1000 |
| commit | 8001b870823b7e17835a7986ba904147764bf2ba (patch) | |
| tree | dac0c5ab9a98347f6cdf504f20b46a09f82da4c9 /src | |
| parent | bb98f2b439ad0b0d7b1116614cba7598f0cd8d44 (diff) | |
Move helper logic inside static_gather
Diffstat (limited to 'src')
| -rw-r--r-- | src/ranges.hh | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/ranges.hh b/src/ranges.hh index affafda9..312c9af5 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -632,31 +632,25 @@ auto gather() }}; } -template<typename ExceptionType, bool exact_size, size_t... Indexes> -auto elements() -{ - return ViewFactory{[=] (auto&& range) { - using std::begin; using std::end; - auto it = begin(range), end_it = end(range); - size_t i = 0; - auto elem = [&](size_t index) { - for (; i < index; ++i) - if (++it == end_it) throw ExceptionType{i}; - return *it; - }; - // Note that initializer lists elements are guaranteed to be sequenced - Array<std::remove_cvref_t<decltype(*begin(range))>, sizeof...(Indexes)> res{{elem(Indexes)...}}; - if (exact_size and ++it != end_it) - throw ExceptionType{++i}; - return res; - }}; -} - template<typename ExceptionType, size_t size, bool exact_size = true> auto static_gather() { return []<size_t... Indexes>(std::index_sequence<Indexes...>) { - return elements<ExceptionType, exact_size, Indexes...>(); + return ViewFactory{[=] (auto&& range) { + using std::begin; using std::end; + auto it = begin(range), end_it = end(range); + size_t i = 0; + auto elem = [&](size_t index) { + for (; i < index; ++i) + if (++it == end_it) throw ExceptionType{i}; + return *it; + }; + // Note that initializer lists elements are guaranteed to be sequenced + Array<std::remove_cvref_t<decltype(*begin(range))>, sizeof...(Indexes)> res{{elem(Indexes)...}}; + if (exact_size and ++it != end_it) + throw ExceptionType{++i}; + return res; + }}; }(std::make_index_sequence<size>()); } |
