summaryrefslogtreecommitdiffstats
path: root/Source/cmAlgorithms.h
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-02-10 21:19:21 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-02-11 21:57:55 (GMT)
commit4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab (patch)
tree2fd78ee3a880d04f2906c6a9383db300e75c99ef /Source/cmAlgorithms.h
parent8910224950a2b723e0d4fd7c21a326af7fb2e050 (diff)
downloadCMake-4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab.zip
CMake-4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab.tar.gz
CMake-4e78ebbdf94b99f7b7d5b9b31d05dd9479b1d6ab.tar.bz2
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.
Diffstat (limited to 'Source/cmAlgorithms.h')
-rw-r--r--Source/cmAlgorithms.h21
1 files changed, 21 insertions, 0 deletions
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<Container, /* valueTypeIsPair = */ true>
}
};
+template<typename const_iterator_>
+struct Range
+{
+ typedef const_iterator_ const_iterator;
+ typedef typename std::iterator_traits<const_iterator>::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<typename Iter1, typename Iter2>
+ContainerAlgorithms::Range<Iter1> cmRange(Iter1 begin, Iter2 end)
+{
+ return ContainerAlgorithms::Range<Iter1>(begin, end);
}
template<typename Container>