[libcxx-commits] [libcxx] 8d4af1b - [libcxx] adds concept std::regular

Christopher Di Bella via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 12 08:54:20 PST 2021


Author: Christopher Di Bella
Date: 2021-03-12T08:54:03-08:00
New Revision: 8d4af1b6e033fc6eba52d862cd93dc8939fea916

URL: https://github.com/llvm/llvm-project/commit/8d4af1b6e033fc6eba52d862cd93dc8939fea916
DIFF: https://github.com/llvm/llvm-project/commit/8d4af1b6e033fc6eba52d862cd93dc8939fea916.diff

LOG: [libcxx] adds concept std::regular

Implements parts of:
    - P0898R3 Standard Library Concepts
    - P1754 Rename concepts to standard_case for C++20, while we still can

Depends on D97911

Reviewed By: EricWF, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D98154

Added: 
    libcxx/test/std/concepts/object/regular.compile.pass.cpp

Modified: 
    libcxx/include/concepts

Removed: 
    


################################################################################
diff  --git a/libcxx/include/concepts b/libcxx/include/concepts
index 930f3c41436a..0a4e7d50c48c 100644
--- a/libcxx/include/concepts
+++ b/libcxx/include/concepts
@@ -385,6 +385,9 @@ concept copyable =
 template<class _Tp>
 concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
 
+template<class _Tp>
+concept regular = semiregular<_Tp> && equality_comparable<_Tp>;
+
 // [concept.invocable]
 template<class _Fn, class... _Args>
 concept invocable = requires(_Fn&& __fn, _Args&&... __args) {

diff  --git a/libcxx/test/std/concepts/object/regular.compile.pass.cpp b/libcxx/test/std/concepts/object/regular.compile.pass.cpp
new file mode 100644
index 000000000000..a70e265984eb
--- /dev/null
+++ b/libcxx/test/std/concepts/object/regular.compile.pass.cpp
@@ -0,0 +1,168 @@
+//===----------------------------------------------------------------------===//
+//
+// 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<class T>
+// concept regular = see below;
+
+#include <concepts>
+
+#include <deque>
+#include <forward_list>
+#include <list>
+#include <map>
+#include <memory>
+#include <optional>
+#include <stdexcept>
+#include <tuple>
+#include <unordered_map>
+#include <vector>
+
+#include "type_classification/moveconstructible.h"
+#include "type_classification/semiregular.h"
+
+static_assert(std::regular<int>);
+static_assert(std::regular<float>);
+static_assert(std::regular<double>);
+static_assert(std::regular<long double>);
+static_assert(std::regular<int volatile>);
+static_assert(std::regular<void*>);
+static_assert(std::regular<int*>);
+static_assert(std::regular<int const*>);
+static_assert(std::regular<int volatile*>);
+static_assert(std::regular<int volatile const*>);
+static_assert(std::regular<int (*)()>);
+
+struct S {};
+static_assert(!std::regular<S>);
+static_assert(std::regular<int S::*>);
+static_assert(std::regular<int (S::*)()>);
+static_assert(std::regular<int (S::*)() noexcept>);
+static_assert(std::regular<int (S::*)() &>);
+static_assert(std::regular<int (S::*)() & noexcept>);
+static_assert(std::regular<int (S::*)() &&>);
+static_assert(std::regular<int (S::*)() && noexcept>);
+static_assert(std::regular<int (S::*)() const>);
+static_assert(std::regular<int (S::*)() const noexcept>);
+static_assert(std::regular<int (S::*)() const&>);
+static_assert(std::regular<int (S::*)() const & noexcept>);
+static_assert(std::regular<int (S::*)() const&&>);
+static_assert(std::regular<int (S::*)() const && noexcept>);
+static_assert(std::regular<int (S::*)() volatile>);
+static_assert(std::regular<int (S::*)() volatile noexcept>);
+static_assert(std::regular<int (S::*)() volatile&>);
+static_assert(std::regular<int (S::*)() volatile & noexcept>);
+static_assert(std::regular<int (S::*)() volatile&&>);
+static_assert(std::regular<int (S::*)() volatile && noexcept>);
+static_assert(std::regular<int (S::*)() const volatile>);
+static_assert(std::regular<int (S::*)() const volatile noexcept>);
+static_assert(std::regular<int (S::*)() const volatile&>);
+static_assert(std::regular<int (S::*)() const volatile & noexcept>);
+static_assert(std::regular<int (S::*)() const volatile&&>);
+static_assert(std::regular<int (S::*)() const volatile && noexcept>);
+
+union U {};
+static_assert(!std::regular<U>);
+static_assert(std::regular<int U::*>);
+static_assert(std::regular<int (U::*)()>);
+static_assert(std::regular<int (U::*)() noexcept>);
+static_assert(std::regular<int (U::*)() &>);
+static_assert(std::regular<int (U::*)() & noexcept>);
+static_assert(std::regular<int (U::*)() &&>);
+static_assert(std::regular<int (U::*)() && noexcept>);
+static_assert(std::regular<int (U::*)() const>);
+static_assert(std::regular<int (U::*)() const noexcept>);
+static_assert(std::regular<int (U::*)() const&>);
+static_assert(std::regular<int (U::*)() const & noexcept>);
+static_assert(std::regular<int (U::*)() const&&>);
+static_assert(std::regular<int (U::*)() const && noexcept>);
+static_assert(std::regular<int (U::*)() volatile>);
+static_assert(std::regular<int (U::*)() volatile noexcept>);
+static_assert(std::regular<int (U::*)() volatile&>);
+static_assert(std::regular<int (U::*)() volatile & noexcept>);
+static_assert(std::regular<int (U::*)() volatile&&>);
+static_assert(std::regular<int (U::*)() volatile && noexcept>);
+static_assert(std::regular<int (U::*)() const volatile>);
+static_assert(std::regular<int (U::*)() const volatile noexcept>);
+static_assert(std::regular<int (U::*)() const volatile&>);
+static_assert(std::regular<int (U::*)() const volatile & noexcept>);
+static_assert(std::regular<int (U::*)() const volatile&&>);
+static_assert(std::regular<int (U::*)() const volatile && noexcept>);
+
+static_assert(std::regular<std::vector<int> >);
+static_assert(std::regular<std::deque<int> >);
+static_assert(std::regular<std::forward_list<int> >);
+static_assert(std::regular<std::list<int> >);
+static_assert(std::regular<std::shared_ptr<std::unique_ptr<int> > >);
+static_assert(std::regular<std::optional<std::vector<int> > >);
+static_assert(std::regular<std::vector<int> >);
+static_assert(std::regular<std::vector<std::unique_ptr<int> > >);
+static_assert(std::semiregular<std::in_place_t> &&
+              !std::regular<std::in_place_t>);
+
+static_assert(!std::regular<has_volatile_member>);
+static_assert(!std::regular<has_array_member>);
+
+// Not objects
+static_assert(!std::regular<void>);
+static_assert(!std::regular<int&>);
+static_assert(!std::regular<int const&>);
+static_assert(!std::regular<int volatile&>);
+static_assert(!std::regular<int const volatile&>);
+static_assert(!std::regular<int&&>);
+static_assert(!std::regular<int const&&>);
+static_assert(!std::regular<int volatile&&>);
+static_assert(!std::regular<int const volatile&&>);
+static_assert(!std::regular<int()>);
+static_assert(!std::regular<int (&)()>);
+static_assert(!std::regular<int[5]>);
+
+// not copyable
+static_assert(!std::regular<std::unique_ptr<int> >);
+static_assert(!std::regular<int const>);
+static_assert(!std::regular<int const volatile>);
+static_assert(!std::regular<volatile_copy_assignment volatile>);
+static_assert(!std::regular<no_copy_constructor>);
+static_assert(!std::regular<no_copy_assignment>);
+static_assert(!std::regular<no_copy_assignment_mutable>);
+static_assert(!std::regular<derived_from_noncopyable>);
+static_assert(!std::regular<has_noncopyable>);
+static_assert(!std::regular<has_const_member>);
+static_assert(!std::regular<has_cv_member>);
+static_assert(!std::regular<has_lvalue_reference_member>);
+static_assert(!std::regular<has_rvalue_reference_member>);
+static_assert(!std::regular<has_function_ref_member>);
+static_assert(!std::regular<deleted_assignment_from_const_rvalue>);
+
+// not default_initializable
+static_assert(!std::regular<std::runtime_error>);
+static_assert(
+    !std::regular<std::tuple<std::runtime_error, std::overflow_error> >);
+static_assert(!std::regular<std::nullopt_t>);
+static_assert(!std::regular<no_copy_constructor>);
+static_assert(!std::regular<no_copy_assignment>);
+static_assert(std::is_copy_assignable_v<no_copy_assignment_mutable> &&
+              !std::regular<no_copy_assignment_mutable>);
+static_assert(!std::regular<derived_from_noncopyable>);
+static_assert(!std::regular<has_noncopyable>);
+
+static_assert(!std::regular<derived_from_non_default_initializable>);
+static_assert(!std::regular<has_non_default_initializable>);
+
+// not equality_comparable
+static_assert(!std::regular<const_copy_assignment const>);
+static_assert(!std::regular<cv_copy_assignment const volatile>);
+
+struct is_equality_comparable {
+  [[nodiscard]] bool operator==(is_equality_comparable const&) const = default;
+};
+static_assert(std::regular<is_equality_comparable>);
+
+int main(int, char**) { return 0; }


        


More information about the libcxx-commits mailing list