summaryrefslogtreecommitdiff
path: root/lib/collections.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-02-25 03:23:07 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-02-25 03:23:07 +0000
commitf25a47f022e45137149a0726a73cbd8b1fda4f04 (patch)
treed57a28af694f2c5d1a0c33ffb174c168f8fcbff2 /lib/collections.hpp
parentPrimitives add named faces (diff)
downloadilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.tar.bz2
ilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.tar.xz
ilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.zip
Helpers to create container instances from ranges
Diffstat (limited to 'lib/collections.hpp')
-rw-r--r--lib/collections.hpp16
1 files changed, 16 insertions, 0 deletions
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<const E *>;
};
+template<typename T>
+concept IterableCollection = std::is_same_v<decltype(std::declval<T>().begin()), decltype(std::declval<T>().end())>;
template<typename T, std::size_t first, std::size_t second>
constexpr std::array<T, first + second>
@@ -102,3 +104,17 @@ vectorOfN(std::integral auto N, unsigned int start = {}, unsigned int step = 1)
});
return v;
}
+
+template<template<typename...> typename Rtn = std::vector, IterableCollection In>
+auto
+materializeRange(In && in)
+{
+ return Rtn(in.begin(), in.end());
+}
+
+template<template<typename...> typename Rtn = std::vector, typename In>
+auto
+materializeRange(const std::pair<In, In> & in)
+{
+ return Rtn(in.first, in.second);
+}