[libcxx-commits] [libcxx] 8054883 - [libc++][ranges] Add subsumption tests to `[special.mem.concepts]`.

Konstantin Varlamov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 12 00:37:47 PST 2021


Author: Konstantin Varlamov
Date: 2021-12-12T00:37:23-08:00
New Revision: 805488358a8c285afc4683272171a4144d57877e

URL: https://github.com/llvm/llvm-project/commit/805488358a8c285afc4683272171a4144d57877e
DIFF: https://github.com/llvm/llvm-project/commit/805488358a8c285afc4683272171a4144d57877e.diff

LOG: [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

Added: 
    

Modified: 
    libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_iterator.compile.pass.cpp
    libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_range.compile.pass.cpp
    libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_iterator.compile.pass.cpp b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_iterator.compile.pass.cpp
index 9f1076d079c61..8567cf2dc9263 100644
--- a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_iterator.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_iterator.compile.pass.cpp
@@ -29,3 +29,10 @@ struct ForwardProxyIterator {
 static_assert(std::ranges::__nothrow_forward_iterator<forward_iterator<int*>>);
 static_assert(std::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"));

diff  --git a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_range.compile.pass.cpp b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_range.compile.pass.cpp
index ba28898035018..2510c729f2bf8 100644
--- a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_range.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_forward_range.compile.pass.cpp
@@ -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::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"));

diff  --git a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp
index dd7ce4708f3ed..7bd97b0115ec0 100644
--- a/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/specialized.algorithms/special.mem.concepts/nothrow_sentinel_for.compile.pass.cpp
@@ -16,3 +16,20 @@
 
 static_assert(std::ranges::__nothrow_sentinel_for<int*, int*>);
 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"));


        


More information about the libcxx-commits mailing list