From f25a47f022e45137149a0726a73cbd8b1fda4f04 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Feb 2023 03:23:07 +0000 Subject: Helpers to create container instances from ranges --- lib/collections.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/collections.hpp') diff --git a/lib/collections.hpp b/lib/collections.hpp index 31e5ab8..18e6147 100644 --- a/lib/collections.hpp +++ b/lib/collections.hpp @@ -15,6 +15,8 @@ concept SequentialCollection = requires(T c) { c.data() } -> std::same_as; }; +template +concept IterableCollection = std::is_same_v().begin()), decltype(std::declval().end())>; template constexpr std::array @@ -102,3 +104,17 @@ vectorOfN(std::integral auto N, unsigned int start = {}, unsigned int step = 1) }); return v; } + +template typename Rtn = std::vector, IterableCollection In> +auto +materializeRange(In && in) +{ + return Rtn(in.begin(), in.end()); +} + +template typename Rtn = std::vector, typename In> +auto +materializeRange(const std::pair & in) +{ + return Rtn(in.first, in.second); +} -- cgit v1.2.3