Commit 9982d892 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 5

Make RangeEnumerator C++17 compliant (Generalizing the Range-Based For Loop)

Summary:
Specifically the loosening of the definition of a range where-by the end of an iterator may be represented by a different type than the beginning of the range.
Oh, and it also fixes compilation on MSVC, which didn't like the decltype being used to determine the iterator type.

Reviewed By: yfeldblum

Differential Revision: D3613993

fbshipit-source-id: 2940a15d0f93c5b6310d0b1896f5d12ca9aec639
parent d150b5b7
...@@ -124,16 +124,17 @@ class Enumerator { ...@@ -124,16 +124,17 @@ class Enumerator {
template <class Range> template <class Range>
class RangeEnumerator { class RangeEnumerator {
Range r_; Range r_;
using Iterator = decltype(r_.begin()); using BeginIteratorType = decltype(std::declval<Range>().begin());
using EndIteratorType = decltype(std::declval<Range>().end());
public: public:
explicit RangeEnumerator(Range&& r) : r_(std::forward<Range>(r)) {} explicit RangeEnumerator(Range&& r) : r_(std::forward<Range>(r)) {}
Enumerator<Iterator> begin() { Enumerator<BeginIteratorType> begin() {
return Enumerator<Iterator>(r_.begin()); return Enumerator<BeginIteratorType>(r_.begin());
} }
Enumerator<Iterator> end() { Enumerator<EndIteratorType> end() {
return Enumerator<Iterator>(r_.end()); return Enumerator<EndIteratorType>(r_.end());
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment