From c7ad02009934ecaea4e2f152ff784ee0d36029a0 Mon Sep 17 00:00:00 2001 From: Christopher Di Bella Date: Wed, 31 Mar 2021 05:28:25 +0000 Subject: [PATCH] [libcxx] adds remaining callable concepts * `std::predicate` * `std::relation` * `std::equivalence_relation` * `std::strict_weak_order` Implements parts of: - P0898R3 Standard Library Concepts - P1754 Rename concepts to standard_case for C++20, while we still can Differential Revision: https://reviews.llvm.org/D96477 --- .../concept.equiv/equivalence_relation.pass.cpp | 61 ++++++++++++++++++++ .../equivalence_relation.subsumption.pass.cpp | 61 ++++++++++++++++++++ .../concept.predicate/predicate.pass.cpp | 65 ++++++++++++++++++++++ .../predicate.subsumption.pass.cpp | 33 +++++++++++ .../concept.relation/relation.pass.cpp | 59 ++++++++++++++++++++ .../concept.relation/relation.subsumption.pass.cpp | 41 ++++++++++++++ .../strict_weak_order.pass.cpp | 60 ++++++++++++++++++++ .../strict_weak_order.subsumption.pass.cpp | 40 +++++++++++++ 8 files changed, 420 insertions(+) create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.subsumption.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.relation/relation.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.relation/relation.subsumption.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.pass.cpp create mode 100644 libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.subsumption.pass.cpp diff --git a/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.pass.cpp new file mode 100644 index 0000000..f925eb5 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept equivalence_relation; + +#include + +static_assert(std::equivalence_relation); +static_assert(std::equivalence_relation); +static_assert(std::equivalence_relation); + +static_assert(!std::equivalence_relation); +static_assert(!std::equivalence_relation); +static_assert(!std::equivalence_relation); + +static_assert( + !std::equivalence_relation); +static_assert(!std::equivalence_relation); + +struct S1 {}; +static_assert(std::relation); +static_assert(std::relation); + +struct S2 {}; + +struct P1 { + bool operator()(S1, S1) const; +}; +static_assert(std::equivalence_relation); + +struct P2 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; +}; +static_assert(!std::equivalence_relation); + +struct P3 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; +}; +static_assert(!std::equivalence_relation); + +struct P4 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(std::equivalence_relation); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.pass.cpp new file mode 100644 index 0000000..0aad734 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept equivalence_relation; + +#include + +// clang-format off +template +requires std::relation +[[nodiscard]] constexpr bool check_subsumption() { return false; } + +template +requires std::equivalence_relation && true +[[nodiscard]] constexpr bool check_subsumption() { return false; } + +template +requires std::equivalence_relation && true +[[nodiscard]] constexpr bool check_subsumption() { return true; } +// clang-format on + +static_assert(check_subsumption()); +static_assert(check_subsumption()); + +struct S1 {}; +struct S2 {}; + +struct R { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(check_subsumption()); +static_assert(check_subsumption()); + +// clang-format off +template +requires std::relation && true +[[nodiscard]] constexpr bool check_reverse_subsumption() { return true; } + +template +requires std::equivalence_relation +[[nodiscard]] constexpr bool check_no_subsumption() { return false; } +// clang-format on + +static_assert(check_reverse_subsumption()); +static_assert(check_reverse_subsumption()); +static_assert(check_reverse_subsumption()); +static_assert(check_reverse_subsumption()); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.pass.cpp new file mode 100644 index 0000000..111f89c --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept predicate; + +#include + +static_assert(std::predicate); +static_assert(std::predicate); +static_assert(std::predicate); + +static_assert(!std::predicate); +static_assert(!std::predicate); +static_assert(!std::predicate); + +struct S {}; + +static_assert(!std::predicate); +static_assert(!std::predicate); +static_assert(std::predicate); +static_assert(std::predicate); +static_assert(std::predicate); +static_assert(!std::predicate); +static_assert(!std::predicate); + +static_assert(!std::predicate); +static_assert(!std::predicate); +static_assert(!std::predicate); +static_assert(std::predicate); + +struct Predicate { + bool operator()(int, double, char); +}; +static_assert(std::predicate); +static_assert(std::predicate); +static_assert(!std::predicate); +static_assert(!std::predicate); + +[[nodiscard]] constexpr bool check_lambda(auto) { return false; } + +[[nodiscard]] constexpr bool check_lambda(std::predicate auto) { return true; } + +static_assert(check_lambda([] { return std::true_type(); })); +static_assert(check_lambda([]() -> int* { return nullptr; })); + +struct boolean { + operator bool() const noexcept; +}; +static_assert(check_lambda([] { return boolean(); })); + +struct explicit_bool { + explicit operator bool() const noexcept; +}; +static_assert(!check_lambda([] { return explicit_bool(); })); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.subsumption.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.subsumption.pass.cpp new file mode 100644 index 0000000..86c79f0 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.predicate/predicate.subsumption.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept predicate; + +#include + +[[nodiscard]] constexpr bool check_subsumption(std::regular_invocable auto) { + return false; +} + +// clang-format off +template +requires std::predicate && true +[[nodiscard]] constexpr bool check_subsumption(F) +{ + return true; +} +// clang-format on + +static_assert(!check_subsumption([] {})); +static_assert(check_subsumption([] { return true; })); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.pass.cpp new file mode 100644 index 0000000..c7617fc --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept relation; + +#include + +static_assert(std::relation); +static_assert(std::relation); +static_assert(std::relation); + +static_assert(!std::relation); +static_assert(!std::relation); +static_assert(!std::relation); +static_assert(!std::relation); +static_assert(!std::relation); + +struct S1 {}; +static_assert(std::relation); +static_assert(std::relation); + +struct S2 {}; + +struct P1 { + bool operator()(S1, S1) const; +}; +static_assert(std::relation); + +struct P2 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; +}; +static_assert(!std::relation); + +struct P3 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; +}; +static_assert(!std::relation); + +struct P4 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(std::relation); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.subsumption.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.subsumption.pass.cpp new file mode 100644 index 0000000..8568bd5 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.relation/relation.subsumption.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept relation; + +#include + +// clang-format off +template +requires std::predicate && std::predicate && + std::predicate && std::predicate +[[nodiscard]] constexpr bool check_subsumption() { return false; } + +template +requires std::relation && true +[[nodiscard]] constexpr bool check_subsumption() { return true; } +// clang-format on + +static_assert(check_subsumption()); + +struct S1 {}; +struct S2 {}; + +struct R { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(check_subsumption()); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.pass.cpp new file mode 100644 index 0000000..437dcd2 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept strict_weak_order; + +#include + +static_assert(std::strict_weak_order); +static_assert(std::strict_weak_order); +static_assert(std::strict_weak_order); + +static_assert(!std::strict_weak_order); +static_assert(!std::strict_weak_order); +static_assert(!std::strict_weak_order); + +static_assert(!std::strict_weak_order); +static_assert(!std::strict_weak_order); + +struct S1 {}; +static_assert(std::strict_weak_order); +static_assert(std::strict_weak_order); + +struct S2 {}; + +struct P1 { + bool operator()(S1, S1) const; +}; +static_assert(std::strict_weak_order); + +struct P2 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; +}; +static_assert(!std::strict_weak_order); + +struct P3 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; +}; +static_assert(!std::strict_weak_order); + +struct P4 { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(std::strict_weak_order); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.subsumption.pass.cpp b/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.subsumption.pass.cpp new file mode 100644 index 0000000..52a19f4 --- /dev/null +++ b/libcxx/test/std/concepts/concepts.callable/concept.strictweakorder/strict_weak_order.subsumption.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept strict_weak_order; + +#include + +// clang-format off +template +requires std::relation +[[nodiscard]] constexpr bool check_subsumption() { return false; } + +template +requires std::strict_weak_order && true +[[nodiscard]] constexpr bool check_subsumption() { return true; } +// clang-format on + +static_assert(check_subsumption()); + +struct S1 {}; +struct S2 {}; + +struct R { + bool operator()(S1, S1) const; + bool operator()(S1, S2) const; + bool operator()(S2, S1) const; + bool operator()(S2, S2) const; +}; +static_assert(check_subsumption()); + +int main(int, char**) { return 0; } -- 2.7.4