From 14849c2df09bccb2aa4f743edbc5179a7c7171f5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 15 Dec 2014 03:22:36 +0100 Subject: [PATCH] convenicence shortcut to expose a container snapshot as iterator basically just a function to pick up the container and element type automatically. The actual implementation is delegated to the exisiting lib::iter_stl::IterSnapshot --- src/lib/iter-adapter-stl.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/lib/iter-adapter-stl.hpp b/src/lib/iter-adapter-stl.hpp index ee7595e8c..703216e53 100644 --- a/src/lib/iter-adapter-stl.hpp +++ b/src/lib/iter-adapter-stl.hpp @@ -524,6 +524,42 @@ namespace iter_stl { } }; + namespace { + template + using ContentSnapshot = IterSnapshot; + } + + + + /** Take a snapshot of the given STL compliant container + * @return Lumiera Forward Iterator to yield each Element from this snapshot + * @note the snapshot is stored within a vector, i.e. heap allocated. + * @warning copying the returned iterator object copies the snapshot vector + */ + template + inline ContentSnapshot + snapshot(CON const& con) + { + return ContentSnapshot(begin(con), end(con)); + } + + /** Take a snapshot of the given \c std::initializer_list + * @return Lumiera Forward Iterator to yield each Element from this snapshot + * @remarks this can be a easy workaround for passing on a sequence of literal + * values defined inline in a brace expression; the typical implementation + * of brace initialiser lists allocates a temporary array on the stack. + * By using this helper, we copy the elements from this local array + * into a vector on the heap. Of course this isn't efficient, + * but it's convenient, e.g. for testing. + */ + template + inline iter_stl::IterSnapshot + snapshot(std::initializer_list const&& ili) + { + using OnceIter = iter_stl::IterSnapshot; + return OnceIter(begin(ili), end(ili)); + } + }} // namespace lib::iter_stl #endif