From 0c12f1ea0da0a5822a7a69b4ff77b45732c72466 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:14:54 +0100 Subject: cmAlgorithms: Add a range adaptor and API for adjusting a range. --- Source/cmAlgorithms.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 6c03f51..ad2b9c1 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -122,6 +122,17 @@ struct Range const_iterator begin() const { return Begin; } const_iterator end() const { return End; } bool empty() const { return std::distance(Begin, End) == 0; } + Range& advance(cmIML_INT_intptr_t amount) + { + std::advance(Begin, amount); + return *this; + } + + Range& retreat(cmIML_INT_intptr_t amount) + { + std::advance(End, -amount); + return *this; + } private: const_iterator Begin; const_iterator End; @@ -135,6 +146,14 @@ ContainerAlgorithms::Range cmRange(Iter1 begin, Iter2 end) return ContainerAlgorithms::Range(begin, end); } +template +ContainerAlgorithms::Range +cmRange(Range const& range) +{ + return ContainerAlgorithms::Range( + range.begin(), range.end()); +} + template void cmDeleteAll(Container const& c) { -- cgit v0.12