From 4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 10 Feb 2015 22:19:21 +0100 Subject: cmAlgorithms: Add a Range container and adaptor method. This can make a pair of iterators API compatible with the cmJoin algorithm and other range-based algorithms. Accept different iterator types in the cmRange adaptor so that a const and non-const iterator are accepted. --- Source/cmAlgorithms.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 4938140..6c03f51 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -112,6 +112,27 @@ struct DefaultDeleter } }; +template +struct Range +{ + typedef const_iterator_ const_iterator; + typedef typename std::iterator_traits::value_type value_type; + Range(const_iterator begin_, const_iterator end_) + : Begin(begin_), End(end_) {} + const_iterator begin() const { return Begin; } + const_iterator end() const { return End; } + bool empty() const { return std::distance(Begin, End) == 0; } +private: + const_iterator Begin; + const_iterator End; +}; + +} + +template +ContainerAlgorithms::Range cmRange(Iter1 begin, Iter2 end) +{ + return ContainerAlgorithms::Range(begin, end); } template -- cgit v0.12