From d75e737de182d11d0293212d6fd0fc2c6732af54 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 17 Mar 2023 02:03:30 +0000 Subject: Allow overriding vectorOfN's returned type --- lib/collections.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/collections.hpp') diff --git a/lib/collections.hpp b/lib/collections.hpp index 16870be..2b83500 100644 --- a/lib/collections.hpp +++ b/lib/collections.hpp @@ -92,11 +92,11 @@ operator+(const std::vector & in, Vn && vn) return out; } -template typename Direction = std::plus> +template typename Direction = std::plus, typename T = unsigned int> [[nodiscard]] static auto -vectorOfN(std::integral auto N, unsigned int start = {}, unsigned int step = 1) +vectorOfN(std::integral auto N, T start = {}, T step = 1) { - std::vector v; + std::vector v; v.resize(N); std::generate_n(v.begin(), N, [&start, step, adj = Direction {}]() { return std::exchange(start, adj(start, step)); -- cgit v1.2.3 From b244b896503065198bc736bbff52d6ff79c24986 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 7 Apr 2023 23:47:26 +0100 Subject: Add helper for iterating over a range defined by a pair of iterators --- lib/collections.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/collections.hpp') diff --git a/lib/collections.hpp b/lib/collections.hpp index 2b83500..59cec6f 100644 --- a/lib/collections.hpp +++ b/lib/collections.hpp @@ -117,3 +117,18 @@ materializeRange(const std::pair & in) { return Rtn(in.first, in.second); } + +template struct pair_range { + constexpr auto & + begin() const noexcept + { + return pair.first; + } + constexpr auto & + end() const noexcept + { + return pair.second; + } + const std::pair & pair; +}; +template pair_range(std::pair) -> pair_range; -- cgit v1.2.3