summaryrefslogtreecommitdiff
path: root/Source/cmRange.h
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-02-15 21:40:41 +0100
committerBrad King <brad.king@kitware.com>2019-02-21 08:24:25 -0500
commit17a367e77f373e2781e80e80aaa32644754e6f88 (patch)
tree9ef45ba0f3b5028bbe781178730d104fc731c690 /Source/cmRange.h
parent9eb0e73f461f168fb036c304de13d7501edf6d12 (diff)
downloadcmake-17a367e77f373e2781e80e80aaa32644754e6f88.tar.gz
cmRange: Stylistic cleanup
Diffstat (limited to 'Source/cmRange.h')
-rw-r--r--Source/cmRange.h64
1 files changed, 34 insertions, 30 deletions
diff --git a/Source/cmRange.h b/Source/cmRange.h
index 5a2f699b59..a84ccecfca 100644
--- a/Source/cmRange.h
+++ b/Source/cmRange.h
@@ -5,73 +5,77 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include "cm_kwiml.h"
#include <algorithm>
#include <iterator>
-template <typename const_iterator_>
-struct cmRange
+template <typename Iter>
+class cmRange
{
- typedef const_iterator_ const_iterator;
- typedef typename std::iterator_traits<const_iterator>::value_type value_type;
- typedef typename std::iterator_traits<const_iterator>::difference_type
- difference_type;
- cmRange(const_iterator begin_, const_iterator end_)
- : Begin(begin_)
- , End(end_)
+public:
+ using const_iterator = Iter;
+ using value_type = typename std::iterator_traits<Iter>::value_type;
+ using difference_type = typename std::iterator_traits<Iter>::difference_type;
+
+ cmRange(Iter b, Iter e)
+ : Begin(std::move(b))
+ , End(std::move(e))
+ {
+ }
+
+ Iter begin() const { return this->Begin; }
+ Iter end() const { return this->End; }
+ bool empty() const { return this->Begin == this->End; }
+
+ difference_type size() const
{
+ return std::distance(this->Begin, this->End);
}
- const_iterator begin() const { return Begin; }
- const_iterator end() const { return End; }
- bool empty() const { return std::distance(Begin, End) == 0; }
- difference_type size() const { return std::distance(Begin, End); }
- cmRange& advance(KWIML_INT_intptr_t amount) &
+ cmRange& advance(difference_type amount) &
{
std::advance(this->Begin, amount);
return *this;
}
- cmRange advance(KWIML_INT_intptr_t amount) &&
+
+ cmRange advance(difference_type amount) &&
{
std::advance(this->Begin, amount);
return std::move(*this);
}
- cmRange& retreat(KWIML_INT_intptr_t amount) &
+ cmRange& retreat(difference_type amount) &
{
- std::advance(End, -amount);
+ std::advance(this->End, -amount);
return *this;
}
- cmRange retreat(KWIML_INT_intptr_t amount) &&
+ cmRange retreat(difference_type amount) &&
{
- std::advance(End, -amount);
+ std::advance(this->End, -amount);
return std::move(*this);
}
private:
- const_iterator Begin;
- const_iterator End;
+ Iter Begin;
+ Iter End;
};
template <typename Iter1, typename Iter2>
-cmRange<Iter1> cmMakeRange(Iter1 begin, Iter2 end)
+auto cmMakeRange(Iter1 begin, Iter2 end) -> cmRange<Iter1>
{
- return cmRange<Iter1>(begin, end);
+ return { begin, end };
}
template <typename Range>
-cmRange<typename Range::const_iterator> cmMakeRange(Range const& range)
+auto cmMakeRange(Range const& range) -> cmRange<decltype(range.begin())>
{
- return cmRange<typename Range::const_iterator>(range.begin(), range.end());
+ return { range.begin(), range.end() };
}
template <typename Range>
-cmRange<typename Range::const_reverse_iterator> cmReverseRange(
- Range const& range)
+auto cmReverseRange(Range const& range) -> cmRange<decltype(range.rbegin())>
{
- return cmRange<typename Range::const_reverse_iterator>(range.rbegin(),
- range.rend());
+ return { range.rbegin(), range.rend() };
}
#endif