зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1646391 - Simplify ReverseIterator. r=froydnj
The following simplifications are made: * Unnecessary function template arguments are removed. * Unnecessary copy constructor definitions are removed (making the types movable where possible). * Iterators are moved where possible rather than copied. * Unnecessary MOZ_IMPLICIT on a constructor with two arguments is removed. Differential Revision: https://phabricator.services.mozilla.com/D80015
This commit is contained in:
Родитель
c1f5273a81
Коммит
2c863dcd11
|
@ -30,12 +30,7 @@ class ReverseIterator {
|
|||
using difference_type = typename IteratorT::difference_type;
|
||||
using iterator_category = typename IteratorT::iterator_category;
|
||||
|
||||
template <typename Iterator>
|
||||
explicit ReverseIterator(Iterator aIter) : mCurrent(aIter) {}
|
||||
|
||||
template <typename Iterator>
|
||||
MOZ_IMPLICIT ReverseIterator(const ReverseIterator<Iterator>& aOther)
|
||||
: mCurrent(aOther.mCurrent) {}
|
||||
explicit ReverseIterator(IteratorT aIter) : mCurrent(std::move(aIter)) {}
|
||||
|
||||
// The return type is not reference, but rather the return type of
|
||||
// Iterator::operator*(), which might be value_type, to allow this to work
|
||||
|
@ -143,13 +138,8 @@ class IteratorRange {
|
|||
typedef ReverseIteratorT reverse_iterator;
|
||||
typedef ReverseIteratorT const_reverse_iterator;
|
||||
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
MOZ_IMPLICIT IteratorRange(Iterator1 aIterBegin, Iterator2 aIterEnd)
|
||||
: mIterBegin(aIterBegin), mIterEnd(aIterEnd) {}
|
||||
|
||||
template <typename Iterator>
|
||||
MOZ_IMPLICIT IteratorRange(const IteratorRange<Iterator>& aOther)
|
||||
: mIterBegin(aOther.mIterBegin), mIterEnd(aOther.mIterEnd) {}
|
||||
IteratorRange(IteratorT aIterBegin, IteratorT aIterEnd)
|
||||
: mIterBegin(std::move(aIterBegin)), mIterEnd(std::move(aIterEnd)) {}
|
||||
|
||||
iterator begin() const { return mIterBegin; }
|
||||
const_iterator cbegin() const { return begin(); }
|
||||
|
|
|
@ -15,7 +15,7 @@ TEST(ReverseIterator, Const_RangeBasedFor)
|
|||
const std::vector<int> in = {1, 2, 3, 4};
|
||||
const auto reversedRange =
|
||||
detail::IteratorRange<ReverseIterator<std::vector<int>::const_iterator>>{
|
||||
in.end(), in.begin()};
|
||||
ReverseIterator{in.end()}, ReverseIterator{in.begin()}};
|
||||
|
||||
const std::vector<int> expected = {4, 3, 2, 1};
|
||||
std::vector<int> out;
|
||||
|
@ -31,7 +31,7 @@ TEST(ReverseIterator, NonConst_RangeBasedFor)
|
|||
std::vector<int> in = {1, 2, 3, 4};
|
||||
auto reversedRange =
|
||||
detail::IteratorRange<ReverseIterator<std::vector<int>::iterator>>{
|
||||
in.end(), in.begin()};
|
||||
ReverseIterator{in.end()}, ReverseIterator{in.begin()}};
|
||||
|
||||
const std::vector<int> expected = {-1, -2, -3, -4};
|
||||
for (auto& i : reversedRange) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче