Files
clang-p2996/libcxx/test/std/ranges/range.adaptors/range.lazy.split/range.lazy.split.inner/equal.pass.cpp
Will Hawkins 808d794a45 [libc++][NFC] Centralize test for support of == and != in ranges (#78481)
Previously, tests for whether comparison using == was supported by
iterators derived from ranges adaptors was spread throughout the testing
codebase. This PR centralizes the implementation of those tests.
2024-04-17 21:32:23 -07:00

73 lines
1.9 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// friend constexpr bool operator==(const inner-iterator& x, const inner-iterator& y);
// requires forward_range<Base>;
//
// friend constexpr bool operator==(const inner-iterator& x, default_sentinel_t);
#include <ranges>
#include <concepts>
#include <string_view>
#include "../types.h"
#include "test_range.h"
constexpr bool test() {
// When `View` is a forward range, `inner-iterator` supports both overloads of `operator==`.
{
SplitViewForward v("abc def", " ");
auto val = *v.begin();
auto b = val.begin();
std::same_as<std::default_sentinel_t> decltype(auto) e = val.end();
// inner-iterator == inner-iterator
{
assert(b == b);
assert(!(b != b));
}
// inner-iterator == default_sentinel
{
assert(!(b == e));
assert(b != e);
assert(!(b == std::default_sentinel));
assert(b != std::default_sentinel);
}
}
// When `View` is an input range, `inner-iterator only supports comparing an `inner-iterator` to the default sentinel.
{
SplitViewInput v("abc def", ' ');
auto val = *v.begin();
auto b = val.begin();
std::same_as<std::default_sentinel_t> decltype(auto) e = val.end();
static_assert(!weakly_equality_comparable_with<decltype(b), decltype(b)>);
assert(!(b == std::default_sentinel));
assert(b != std::default_sentinel);
assert(!(b == e));
assert(b != e);
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}