[libc++][ranges] Add subsumption tests to `[special.mem.concepts]`.

Test that `nothrow-forward-iterator` subsumes `nothrow-input-iterator`,
`nothrow-forward-range` subsumes `nothrow-input-range`, and
`nothrow-sentinel-for` and `sentinel_for` subsume each other.

This is a follow-up to [D114761](https://reviews.llvm.org/D114761).

Differential Revision: https://reviews.llvm.org/D115422
This commit is contained in:
Konstantin Varlamov 2021-12-12 00:37:02 -08:00
parent 474e1bc96d
commit 805488358a
3 changed files with 31 additions and 0 deletions

View File

@ -29,3 +29,10 @@ struct ForwardProxyIterator {
static_assert(std::ranges::__nothrow_forward_iterator<forward_iterator<int*>>); static_assert(std::ranges::__nothrow_forward_iterator<forward_iterator<int*>>);
static_assert(std::forward_iterator<ForwardProxyIterator>); static_assert(std::forward_iterator<ForwardProxyIterator>);
static_assert(!std::ranges::__nothrow_forward_iterator<ForwardProxyIterator>); static_assert(!std::ranges::__nothrow_forward_iterator<ForwardProxyIterator>);
constexpr bool forward_subsumes_input(std::ranges::__nothrow_forward_iterator auto) {
return true;
}
constexpr bool forward_subsumes_input(std::ranges::__nothrow_input_iterator auto);
static_assert(forward_subsumes_input("foo"));

View File

@ -33,3 +33,10 @@ static_assert(std::ranges::__nothrow_forward_range<test_range<forward_iterator>>
static_assert(!std::ranges::__nothrow_forward_range<test_range<cpp20_input_iterator>>); static_assert(!std::ranges::__nothrow_forward_range<test_range<cpp20_input_iterator>>);
static_assert(std::ranges::forward_range<test_range<ForwardProxyIterator>>); static_assert(std::ranges::forward_range<test_range<ForwardProxyIterator>>);
static_assert(!std::ranges::__nothrow_forward_range<test_range<ForwardProxyIterator>>); static_assert(!std::ranges::__nothrow_forward_range<test_range<ForwardProxyIterator>>);
constexpr bool forward_subsumes_input(std::ranges::__nothrow_forward_range auto&&) {
return true;
}
constexpr bool forward_subsumes_input(std::ranges::__nothrow_input_range auto&&);
static_assert(forward_subsumes_input("foo"));

View File

@ -16,3 +16,20 @@
static_assert(std::ranges::__nothrow_sentinel_for<int*, int*>); static_assert(std::ranges::__nothrow_sentinel_for<int*, int*>);
static_assert(!std::ranges::__nothrow_sentinel_for<int*, long*>); static_assert(!std::ranges::__nothrow_sentinel_for<int*, long*>);
// Because `__nothrow_sentinel_for` is essentially an alias for `sentinel_for`,
// the two concepts should subsume each other.
constexpr bool ntsf_subsumes_sf(std::ranges::__nothrow_sentinel_for<char*> auto) requires true {
return true;
}
constexpr bool ntsf_subsumes_sf(std::sentinel_for<char*> auto);
static_assert(ntsf_subsumes_sf("foo"));
constexpr bool sf_subsumes_ntsf(std::sentinel_for<char*> auto) requires true {
return true;
}
constexpr bool sf_subsumes_ntsf(std::ranges::__nothrow_sentinel_for<char*> auto);
static_assert(sf_subsumes_ntsf("foo"));