From e1a41c64de5a3ef72e544a54b77f706d2201a4c2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 26 Dec 2017 17:31:17 +1100 Subject: [PATCH] view: add increment and decrement methods --- view.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/view.hpp b/view.hpp index c21c7e92..5a1d34d9 100644 --- a/view.hpp +++ b/view.hpp @@ -172,6 +172,43 @@ namespace util { return view { m_begin, m_begin + count }; }; + + //--------------------------------------------------------------------- + // returns a view that has the same end iterator, but the provided + // begin iterator. + // + // the new begin iterator must be reachable by incrementing the current + // begin iterator but lie before reaching the end iterator. ie, in the + // middle. + // + // useful for resizing views after options which incrementally consume + // the referenced data. + [[gnu::warn_unused_result]] constexpr auto + increment (IteratorA _begin) const + { + return view { _begin, m_end }; + } + + + //--------------------------------------------------------------------- + [[gnu::warn_unused_result]] constexpr auto + increment (int count) const + { + IteratorA next; + std::advance (next, count); + return increment (next); + } + + + //--------------------------------------------------------------------- + template + [[gnu::warn_unused_result]] constexpr auto + decrement (IteratorC _end) + { + return view { m_begin, _end }; + }; + + /////////////////////////////////////////////////////////////////////// constexpr value_type& operator[] (size_t idx)& noexcept