forked from OSchip/llvm-project
[libc++] [test_iterators] Make all ADL base() functions into hidden friends. NFCI.
This follows up on my addition of base(cpp20_input_iterator) in D115177, making all the ADL base() functions consistent. Also align cpp20_input_iterator with the other test iterators' style. Reviewed as part of D115272.
This commit is contained in:
parent
aff028f7d8
commit
67c43d87cd
|
@ -42,6 +42,8 @@ public:
|
|||
TEST_CONSTEXPR_CXX14 output_iterator operator++(int)
|
||||
{output_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const output_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
@ -81,6 +83,8 @@ public:
|
|||
friend TEST_CONSTEXPR_CXX14 bool operator!=(const cpp17_input_iterator& x, const cpp17_input_iterator& y)
|
||||
{return !(x == y);}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const cpp17_input_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
@ -129,6 +133,8 @@ public:
|
|||
friend TEST_CONSTEXPR_CXX14 bool operator!=(const forward_iterator& x, const forward_iterator& y)
|
||||
{return !(x == y);}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const forward_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
@ -229,6 +235,8 @@ public:
|
|||
TEST_CONSTEXPR_CXX14 bidirectional_iterator operator--(int)
|
||||
{bidirectional_iterator tmp(*this); --(*this); return tmp;}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const bidirectional_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
@ -289,6 +297,8 @@ public:
|
|||
|
||||
TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const random_access_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
@ -419,32 +429,14 @@ public:
|
|||
return x.base() != y.base();
|
||||
}
|
||||
|
||||
friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
#endif
|
||||
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(output_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(cpp17_input_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(forward_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(bidirectional_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(random_access_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
#if TEST_STD_VER > 17
|
||||
template <class Iter>
|
||||
TEST_CONSTEXPR_CXX14 Iter base(contiguous_iterator<Iter> i) { return i.base(); }
|
||||
#endif
|
||||
|
||||
template <class Iter> // everything else
|
||||
template <class Iter> // ADL base() for everything else (including pointers)
|
||||
TEST_CONSTEXPR_CXX14 Iter base(Iter i) { return i; }
|
||||
|
||||
template <typename T>
|
||||
|
@ -628,42 +620,30 @@ private:
|
|||
|
||||
#ifdef TEST_SUPPORTS_RANGES
|
||||
|
||||
template <class I>
|
||||
struct cpp20_input_iterator {
|
||||
using value_type = std::iter_value_t<I>;
|
||||
using difference_type = std::iter_difference_t<I>;
|
||||
template <class It>
|
||||
class cpp20_input_iterator
|
||||
{
|
||||
It it_;
|
||||
|
||||
public:
|
||||
using value_type = std::iter_value_t<It>;
|
||||
using difference_type = std::iter_difference_t<It>;
|
||||
using iterator_concept = std::input_iterator_tag;
|
||||
|
||||
cpp20_input_iterator() = delete;
|
||||
|
||||
constexpr explicit cpp20_input_iterator(It it) : it_(it) {}
|
||||
cpp20_input_iterator(cpp20_input_iterator&&) = default;
|
||||
cpp20_input_iterator& operator=(cpp20_input_iterator&&) = default;
|
||||
constexpr decltype(auto) operator*() const { return *it_; }
|
||||
constexpr cpp20_input_iterator& operator++() { ++it_; return *this; }
|
||||
constexpr void operator++(int) { ++it_; }
|
||||
|
||||
cpp20_input_iterator(cpp20_input_iterator const&) = delete;
|
||||
cpp20_input_iterator& operator=(cpp20_input_iterator const&) = delete;
|
||||
constexpr const It& base() const& { return it_; }
|
||||
constexpr It base() && { return std::move(it_); }
|
||||
|
||||
explicit constexpr cpp20_input_iterator(I base) : base_(std::move(base)) {}
|
||||
|
||||
constexpr decltype(auto) operator*() const { return *base_; }
|
||||
|
||||
constexpr cpp20_input_iterator& operator++() {
|
||||
++base_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator++(int) { ++base_; }
|
||||
|
||||
constexpr const I& base() const& { return base_; }
|
||||
|
||||
constexpr I base() && { return std::move(base_); }
|
||||
|
||||
friend constexpr I base(const cpp20_input_iterator& i) { return i.base_; }
|
||||
friend constexpr It base(const cpp20_input_iterator& i) { return i.it_; }
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
|
||||
private:
|
||||
I base_ = I();
|
||||
};
|
||||
|
||||
template <std::input_or_output_iterator I>
|
||||
|
@ -960,15 +940,15 @@ public:
|
|||
|
||||
constexpr reference operator[](difference_type n) const {return it_[n];}
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
|
||||
friend constexpr
|
||||
difference_type operator-(const three_way_contiguous_iterator& x, const three_way_contiguous_iterator& y) {
|
||||
return x.base() - y.base();
|
||||
}
|
||||
|
||||
friend auto operator<=>(const three_way_contiguous_iterator&, const three_way_contiguous_iterator&) = default;
|
||||
|
||||
template <class T>
|
||||
void operator,(T const &) = delete;
|
||||
};
|
||||
|
||||
#endif // TEST_STD_VER > 17 && defined(__cpp_lib_concepts)
|
||||
|
|
Loading…
Reference in New Issue