From dd2515de6c51c7951a4ba541158df1a8c4415807 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 1 Jan 2018 21:06:25 +0100 Subject: [PATCH] add a utility func to construct a container using a range --- ostd/range.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ostd/range.hh b/ostd/range.hh index 6d2a3d0..8a43341 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -2036,6 +2036,22 @@ namespace detail { }; } +/** @brief Creates a `Container` from `range`. + * + * Standard sequence containers usually support construction from an + * iterator pair. This is a utility function that will create a sequence + * container of the given type using an ostd::input_range's `iter_begin()` + * and `iter_end()` methods. + * + * The remaining arguments are passed after the two iterators. + */ +template +inline Container from_range(InputRange range, Args &&...args) { + return Container( + range.iter_begin(), range.iter_end(), std::forward(args)... + ); +} + /** @} */ } /* namespace ostd */