[libcxx-commits] [libcxx] 1543955 - [libcxx] adds concept std::semiregular
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 11 23:04:07 PST 2021
Author: Christopher Di Bella
Date: 2021-03-11T22:40:07-08:00
New Revision: 154395536e3cd9b39141b306ebb6f41620d4f53f
URL: https://github.com/llvm/llvm-project/commit/154395536e3cd9b39141b306ebb6f41620d4f53f
DIFF: https://github.com/llvm/llvm-project/commit/154395536e3cd9b39141b306ebb6f41620d4f53f.diff
LOG: [libcxx] adds concept std::semiregular
Implements parts of:
- P0898R3 Standard Library Concepts
- P1754 Rename concepts to standard_case for C++20, while we still can
Depends on D97443
Reviewed By: Quuxplusone, EricWF, #libc
Differential Revision: https://reviews.llvm.org/D97911
Added:
libcxx/test/std/concepts/object/semiregular.compile.pass.cpp
libcxx/test/support/type_classification/semiregular.h
Modified:
libcxx/include/concepts
libcxx/test/std/concepts/object/copyable.compile.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/concepts b/libcxx/include/concepts
index cb571b424553..930f3c41436a 100644
--- a/libcxx/include/concepts
+++ b/libcxx/include/concepts
@@ -382,6 +382,9 @@ concept copyable =
assignable_from<_Tp&, const _Tp&> &&
assignable_from<_Tp&, const _Tp>;
+template<class _Tp>
+concept semiregular = copyable<_Tp> && default_initializable<_Tp>;
+
// [concept.invocable]
template<class _Fn, class... _Args>
concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
diff --git a/libcxx/test/std/concepts/object/copyable.compile.pass.cpp b/libcxx/test/std/concepts/object/copyable.compile.pass.cpp
index 605308fbe3c7..9d589f937879 100644
--- a/libcxx/test/std/concepts/object/copyable.compile.pass.cpp
+++ b/libcxx/test/std/concepts/object/copyable.compile.pass.cpp
@@ -9,7 +9,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts
-// template<class From>
+// template<class T>
// concept copyable = see below;
#include <concepts>
diff --git a/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp b/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp
new file mode 100644
index 000000000000..19c773f04369
--- /dev/null
+++ b/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp
@@ -0,0 +1,131 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 semiregular = 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/semiregular.h"
+
+static_assert(std::semiregular<int>);
+static_assert(std::semiregular<int volatile>);
+static_assert(std::semiregular<int*>);
+static_assert(std::semiregular<int const*>);
+static_assert(std::semiregular<int volatile*>);
+static_assert(std::semiregular<int volatile const*>);
+static_assert(std::semiregular<int (*)()>);
+
+struct S {};
+static_assert(std::semiregular<S>);
+static_assert(std::semiregular<int S::*>);
+static_assert(std::semiregular<int (S::*)()>);
+static_assert(std::semiregular<int (S::*)() noexcept>);
+static_assert(std::semiregular<int (S::*)() &>);
+static_assert(std::semiregular<int (S::*)() & noexcept>);
+static_assert(std::semiregular<int (S::*)() &&>);
+static_assert(std::semiregular<int (S::*)() && noexcept>);
+static_assert(std::semiregular<int (S::*)() const>);
+static_assert(std::semiregular<int (S::*)() const noexcept>);
+static_assert(std::semiregular<int (S::*)() const&>);
+static_assert(std::semiregular<int (S::*)() const & noexcept>);
+static_assert(std::semiregular<int (S::*)() const&&>);
+static_assert(std::semiregular<int (S::*)() const && noexcept>);
+static_assert(std::semiregular<int (S::*)() volatile>);
+static_assert(std::semiregular<int (S::*)() volatile noexcept>);
+static_assert(std::semiregular<int (S::*)() volatile&>);
+static_assert(std::semiregular<int (S::*)() volatile & noexcept>);
+static_assert(std::semiregular<int (S::*)() volatile&&>);
+static_assert(std::semiregular<int (S::*)() volatile && noexcept>);
+static_assert(std::semiregular<int (S::*)() const volatile>);
+static_assert(std::semiregular<int (S::*)() const volatile noexcept>);
+static_assert(std::semiregular<int (S::*)() const volatile&>);
+static_assert(std::semiregular<int (S::*)() const volatile & noexcept>);
+static_assert(std::semiregular<int (S::*)() const volatile&&>);
+static_assert(std::semiregular<int (S::*)() const volatile && noexcept>);
+
+static_assert(std::semiregular<std::vector<int> >);
+static_assert(std::semiregular<std::deque<int> >);
+static_assert(std::semiregular<std::forward_list<int> >);
+static_assert(std::semiregular<std::list<int> >);
+static_assert(std::semiregular<std::shared_ptr<std::unique_ptr<int> > >);
+static_assert(std::semiregular<std::optional<std::vector<int> > >);
+static_assert(std::semiregular<std::vector<int> >);
+static_assert(std::semiregular<std::vector<std::unique_ptr<int> > >);
+
+static_assert(std::semiregular<has_volatile_member>);
+static_assert(std::semiregular<has_array_member>);
+
+// Not objects
+static_assert(!std::semiregular<void>);
+static_assert(!std::semiregular<int&>);
+static_assert(!std::semiregular<int const&>);
+static_assert(!std::semiregular<int volatile&>);
+static_assert(!std::semiregular<int const volatile&>);
+static_assert(!std::semiregular<int&&>);
+static_assert(!std::semiregular<int const&&>);
+static_assert(!std::semiregular<int volatile&&>);
+static_assert(!std::semiregular<int const volatile&&>);
+static_assert(!std::semiregular<int()>);
+static_assert(!std::semiregular<int (&)()>);
+static_assert(!std::semiregular<int[5]>);
+
+// Not copyable
+static_assert(!std::semiregular<std::unique_ptr<int> >);
+static_assert(!std::semiregular<int const>);
+static_assert(!std::semiregular<int const volatile>);
+static_assert(std::semiregular<const_copy_assignment const>);
+static_assert(!std::semiregular<volatile_copy_assignment volatile>);
+static_assert(std::semiregular<cv_copy_assignment const volatile>);
+static_assert(!std::semiregular<no_copy_constructor>);
+static_assert(!std::semiregular<no_copy_assignment>);
+static_assert(!std::semiregular<no_copy_assignment_mutable>);
+static_assert(!std::semiregular<derived_from_noncopyable>);
+static_assert(!std::semiregular<has_noncopyable>);
+static_assert(!std::semiregular<has_const_member>);
+static_assert(!std::semiregular<has_cv_member>);
+static_assert(!std::semiregular<has_lvalue_reference_member>);
+static_assert(!std::semiregular<has_rvalue_reference_member>);
+static_assert(!std::semiregular<has_function_ref_member>);
+static_assert(!std::semiregular<deleted_assignment_from_const_rvalue>);
+
+// Not default_initialzable
+static_assert(!std::semiregular<std::runtime_error>);
+static_assert(
+ !std::semiregular<std::tuple<std::runtime_error, std::overflow_error> >);
+static_assert(!std::semiregular<std::nullopt_t>);
+static_assert(!std::semiregular<no_copy_constructor>);
+static_assert(!std::semiregular<no_copy_assignment>);
+static_assert(std::is_copy_assignable_v<no_copy_assignment_mutable>);
+static_assert(!std::semiregular<no_copy_assignment_mutable>);
+static_assert(!std::semiregular<derived_from_noncopyable>);
+static_assert(!std::semiregular<has_noncopyable>);
+
+static_assert(!std::semiregular<no_default_ctor>);
+static_assert(!std::semiregular<derived_from_non_default_initializable>);
+static_assert(!std::semiregular<has_non_default_initializable>);
+
+static_assert(!std::semiregular<deleted_default_ctor>);
+static_assert(!std::semiregular<derived_from_deleted_default_ctor>);
+static_assert(!std::semiregular<has_deleted_default_ctor>);
+
+int main(int, char**) { return 0; }
diff --git a/libcxx/test/support/type_classification/semiregular.h b/libcxx/test/support/type_classification/semiregular.h
new file mode 100644
index 000000000000..98e7f7d3de32
--- /dev/null
+++ b/libcxx/test/support/type_classification/semiregular.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#ifndef TEST_SUPPORT_TYPE_CLASSIFICATION_H
+#define TEST_SUPPORT_TYPE_CLASSIFICATION_H
+
+#include "copyable.h"
+
+struct no_default_ctor {
+ no_default_ctor(int);
+};
+struct derived_from_non_default_initializable : no_default_ctor {};
+struct has_non_default_initializable {
+ no_default_ctor x;
+};
+
+struct deleted_default_ctor {
+ deleted_default_ctor() = delete;
+};
+struct derived_from_deleted_default_ctor : deleted_default_ctor {};
+struct has_deleted_default_ctor {
+ deleted_default_ctor x;
+};
+
+#endif // TEST_SUPPORT_TYPE_CLASSIFICATION_H
More information about the libcxx-commits
mailing list