forked from OSchip/llvm-project
[libc++] Refactor the test for join_view's default constructor
In particular, this removes the need for adding a ad-hoc `operator==` to forward_iterator. Differential Revision: https://reviews.llvm.org/D116614
This commit is contained in:
parent
d2cc6c2d0c
commit
7893bb7408
|
@ -12,45 +12,46 @@
|
||||||
|
|
||||||
// iterator() requires default_initializable<OuterIter> = default;
|
// iterator() requires default_initializable<OuterIter> = default;
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
#include "test_macros.h"
|
#include <cassert>
|
||||||
|
#include <type_traits>
|
||||||
|
#include "test_iterators.h"
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
|
|
||||||
template<class T>
|
template <class It>
|
||||||
struct DefaultCtorParent : std::ranges::view_base {
|
struct view : std::ranges::view_base {
|
||||||
T *ptr_;
|
It begin() const;
|
||||||
constexpr DefaultCtorParent(T *ptr) : ptr_(ptr) {}
|
sentinel_wrapper<It> end() const;
|
||||||
|
|
||||||
constexpr forward_iterator<T *> begin() { return forward_iterator<T *>(ptr_); }
|
|
||||||
constexpr forward_iterator<const T *> begin() const { return forward_iterator<const T *>(ptr_); }
|
|
||||||
constexpr T *end() { return ptr_ + 4; }
|
|
||||||
constexpr const T *end() const { return ptr_ + 4; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template <class It>
|
||||||
constexpr bool operator==(const forward_iterator<T*> &lhs, const T *rhs) { return lhs.base() == rhs; }
|
constexpr void test_default_constructible() {
|
||||||
template<class T>
|
using JoinView = std::ranges::join_view<view<It>>;
|
||||||
constexpr bool operator==(const T *lhs, const forward_iterator<T*> &rhs) { return rhs.base() == lhs; }
|
using JoinIterator = std::ranges::iterator_t<JoinView>;
|
||||||
|
static_assert(std::is_default_constructible_v<JoinIterator>);
|
||||||
|
JoinIterator it; (void)it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
constexpr void test_non_default_constructible() {
|
||||||
|
using JoinView = std::ranges::join_view<view<It>>;
|
||||||
|
using JoinIterator = std::ranges::iterator_t<JoinView>;
|
||||||
|
static_assert(!std::is_default_constructible_v<JoinIterator>);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr bool test() {
|
constexpr bool test() {
|
||||||
using Base = DefaultCtorParent<ChildView>;
|
test_non_default_constructible<cpp17_input_iterator<ChildView*>>();
|
||||||
// Note, only the outer iterator is default_initializable:
|
// NOTE: cpp20_input_iterator can't be used with join_view because it is not copyable.
|
||||||
static_assert( std::default_initializable<std::ranges::iterator_t<Base>>);
|
test_default_constructible<forward_iterator<ChildView*>>();
|
||||||
static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::range_reference_t<Base>>>);
|
test_default_constructible<bidirectional_iterator<ChildView*>>();
|
||||||
|
test_default_constructible<random_access_iterator<ChildView*>>();
|
||||||
std::ranges::iterator_t<std::ranges::join_view<Base>> iter1;
|
test_default_constructible<contiguous_iterator<ChildView*>>();
|
||||||
(void) iter1;
|
|
||||||
|
|
||||||
static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::join_view<ParentView<ChildView>>>>);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
test();
|
test();
|
||||||
static_assert(test());
|
static_assert(test());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue