diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-02-25 03:23:07 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-02-25 03:23:07 +0000 |
commit | f25a47f022e45137149a0726a73cbd8b1fda4f04 (patch) | |
tree | d57a28af694f2c5d1a0c33ffb174c168f8fcbff2 | |
parent | Primitives add named faces (diff) | |
download | ilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.tar.bz2 ilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.tar.xz ilt-f25a47f022e45137149a0726a73cbd8b1fda4f04.zip |
Helpers to create container instances from ranges
-rw-r--r-- | lib/collections.hpp | 16 |
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); +} |