diff --git a/libcxx/include/concepts b/libcxx/include/concepts --- a/libcxx/include/concepts +++ b/libcxx/include/concepts @@ -382,6 +382,9 @@ assignable_from<_Tp&, const _Tp&> && assignable_from<_Tp&, const _Tp>; +template +concept semiregular = copyable<_Tp> && default_initializable<_Tp>; + // [concept.invocable] template 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 --- 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 +// template // concept copyable = see below; #include 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 --- /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 +// concept semiregular = see below; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "type_classification/semiregular.h" + +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); + +struct S {}; +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); + +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular > >); +static_assert(std::semiregular > >); +static_assert(std::semiregular >); +static_assert(std::semiregular > >); + +static_assert(std::semiregular); +static_assert(std::semiregular); + +// Not objects +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +// Not copyable +static_assert(!std::semiregular >); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(std::semiregular); +static_assert(!std::semiregular); +static_assert(std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +// Not default_initialzable +static_assert(!std::semiregular); +static_assert( + !std::semiregular >); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(std::is_copy_assignable_v); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +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 --- /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