xref: /llvm-project/libcxx/test/std/concepts/concepts.object/regular.compile.pass.cpp (revision 72f0edf3f4291d2614719a8c8af21a7a62ed5d74)
124dd2d2fSChristopher Di Bella //===----------------------------------------------------------------------===//
224dd2d2fSChristopher Di Bella //
324dd2d2fSChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
424dd2d2fSChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
524dd2d2fSChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
624dd2d2fSChristopher Di Bella //
724dd2d2fSChristopher Di Bella //===----------------------------------------------------------------------===//
824dd2d2fSChristopher Di Bella 
924dd2d2fSChristopher Di Bella // UNSUPPORTED: c++03, c++11, c++14, c++17
1024dd2d2fSChristopher Di Bella 
1124dd2d2fSChristopher Di Bella // template<class T>
1224dd2d2fSChristopher Di Bella // concept regular = see below;
1324dd2d2fSChristopher Di Bella 
1424dd2d2fSChristopher Di Bella #include <concepts>
1524dd2d2fSChristopher Di Bella 
1624dd2d2fSChristopher Di Bella #include <deque>
1724dd2d2fSChristopher Di Bella #include <forward_list>
1824dd2d2fSChristopher Di Bella #include <list>
1924dd2d2fSChristopher Di Bella #include <map>
2024dd2d2fSChristopher Di Bella #include <memory>
2124dd2d2fSChristopher Di Bella #include <optional>
2224dd2d2fSChristopher Di Bella #include <stdexcept>
2324dd2d2fSChristopher Di Bella #include <tuple>
2424dd2d2fSChristopher Di Bella #include <unordered_map>
2524dd2d2fSChristopher Di Bella #include <vector>
2624dd2d2fSChristopher Di Bella 
2724dd2d2fSChristopher Di Bella #include "type_classification/moveconstructible.h"
2824dd2d2fSChristopher Di Bella #include "type_classification/semiregular.h"
2924dd2d2fSChristopher Di Bella 
3024dd2d2fSChristopher Di Bella static_assert(std::regular<int>);
3124dd2d2fSChristopher Di Bella static_assert(std::regular<float>);
3224dd2d2fSChristopher Di Bella static_assert(std::regular<double>);
3324dd2d2fSChristopher Di Bella static_assert(std::regular<long double>);
3424dd2d2fSChristopher Di Bella static_assert(std::regular<int volatile>);
3524dd2d2fSChristopher Di Bella static_assert(std::regular<void*>);
3624dd2d2fSChristopher Di Bella static_assert(std::regular<int*>);
3724dd2d2fSChristopher Di Bella static_assert(std::regular<int const*>);
3824dd2d2fSChristopher Di Bella static_assert(std::regular<int volatile*>);
3924dd2d2fSChristopher Di Bella static_assert(std::regular<int volatile const*>);
4024dd2d2fSChristopher Di Bella static_assert(std::regular<int (*)()>);
4124dd2d2fSChristopher Di Bella 
4224dd2d2fSChristopher Di Bella struct S {};
4324dd2d2fSChristopher Di Bella static_assert(!std::regular<S>);
4424dd2d2fSChristopher Di Bella static_assert(std::regular<int S::*>);
4524dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)()>);
4624dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() noexcept>);
4724dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() &>);
4824dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() & noexcept>);
4924dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() &&>);
5024dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() && noexcept>);
5124dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const>);
5224dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const noexcept>);
5324dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const&>);
5424dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const & noexcept>);
5524dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const&&>);
5624dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const && noexcept>);
5724dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile>);
5824dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile noexcept>);
5924dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile&>);
6024dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile & noexcept>);
6124dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile&&>);
6224dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() volatile && noexcept>);
6324dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile>);
6424dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile noexcept>);
6524dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile&>);
6624dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile & noexcept>);
6724dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile&&>);
6824dd2d2fSChristopher Di Bella static_assert(std::regular<int (S::*)() const volatile && noexcept>);
6924dd2d2fSChristopher Di Bella 
7024dd2d2fSChristopher Di Bella union U {};
7124dd2d2fSChristopher Di Bella static_assert(!std::regular<U>);
7224dd2d2fSChristopher Di Bella static_assert(std::regular<int U::*>);
7324dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)()>);
7424dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() noexcept>);
7524dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() &>);
7624dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() & noexcept>);
7724dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() &&>);
7824dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() && noexcept>);
7924dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const>);
8024dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const noexcept>);
8124dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const&>);
8224dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const & noexcept>);
8324dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const&&>);
8424dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const && noexcept>);
8524dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile>);
8624dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile noexcept>);
8724dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile&>);
8824dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile & noexcept>);
8924dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile&&>);
9024dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() volatile && noexcept>);
9124dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile>);
9224dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile noexcept>);
9324dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile&>);
9424dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile & noexcept>);
9524dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile&&>);
9624dd2d2fSChristopher Di Bella static_assert(std::regular<int (U::*)() const volatile && noexcept>);
9724dd2d2fSChristopher Di Bella 
9824dd2d2fSChristopher Di Bella static_assert(std::regular<std::vector<int> >);
9924dd2d2fSChristopher Di Bella static_assert(std::regular<std::deque<int> >);
10024dd2d2fSChristopher Di Bella static_assert(std::regular<std::forward_list<int> >);
10124dd2d2fSChristopher Di Bella static_assert(std::regular<std::list<int> >);
10224dd2d2fSChristopher Di Bella static_assert(std::regular<std::shared_ptr<std::unique_ptr<int> > >);
10324dd2d2fSChristopher Di Bella static_assert(std::regular<std::optional<std::vector<int> > >);
10424dd2d2fSChristopher Di Bella static_assert(std::regular<std::vector<int> >);
10524dd2d2fSChristopher Di Bella static_assert(std::regular<std::vector<std::unique_ptr<int> > >);
10624dd2d2fSChristopher Di Bella static_assert(std::semiregular<std::in_place_t> &&
10724dd2d2fSChristopher Di Bella               !std::regular<std::in_place_t>);
10824dd2d2fSChristopher Di Bella 
10924dd2d2fSChristopher Di Bella static_assert(!std::regular<has_volatile_member>);
11024dd2d2fSChristopher Di Bella static_assert(!std::regular<has_array_member>);
11124dd2d2fSChristopher Di Bella 
11224dd2d2fSChristopher Di Bella // Not objects
11324dd2d2fSChristopher Di Bella static_assert(!std::regular<void>);
11424dd2d2fSChristopher Di Bella static_assert(!std::regular<int&>);
11524dd2d2fSChristopher Di Bella static_assert(!std::regular<int const&>);
11624dd2d2fSChristopher Di Bella static_assert(!std::regular<int volatile&>);
11724dd2d2fSChristopher Di Bella static_assert(!std::regular<int const volatile&>);
11824dd2d2fSChristopher Di Bella static_assert(!std::regular<int&&>);
11924dd2d2fSChristopher Di Bella static_assert(!std::regular<int const&&>);
12024dd2d2fSChristopher Di Bella static_assert(!std::regular<int volatile&&>);
12124dd2d2fSChristopher Di Bella static_assert(!std::regular<int const volatile&&>);
12224dd2d2fSChristopher Di Bella static_assert(!std::regular<int()>);
12324dd2d2fSChristopher Di Bella static_assert(!std::regular<int (&)()>);
12424dd2d2fSChristopher Di Bella static_assert(!std::regular<int[5]>);
12524dd2d2fSChristopher Di Bella 
12624dd2d2fSChristopher Di Bella // not copyable
12724dd2d2fSChristopher Di Bella static_assert(!std::regular<std::unique_ptr<int> >);
12824dd2d2fSChristopher Di Bella static_assert(!std::regular<int const>);
12924dd2d2fSChristopher Di Bella static_assert(!std::regular<int const volatile>);
13024dd2d2fSChristopher Di Bella static_assert(!std::regular<volatile_copy_assignment volatile>);
13124dd2d2fSChristopher Di Bella static_assert(!std::regular<no_copy_constructor>);
13224dd2d2fSChristopher Di Bella static_assert(!std::regular<no_copy_assignment>);
13324dd2d2fSChristopher Di Bella static_assert(!std::regular<no_copy_assignment_mutable>);
13424dd2d2fSChristopher Di Bella static_assert(!std::regular<derived_from_noncopyable>);
13524dd2d2fSChristopher Di Bella static_assert(!std::regular<has_noncopyable>);
13624dd2d2fSChristopher Di Bella static_assert(!std::regular<has_const_member>);
13724dd2d2fSChristopher Di Bella static_assert(!std::regular<has_cv_member>);
13824dd2d2fSChristopher Di Bella static_assert(!std::regular<has_lvalue_reference_member>);
13924dd2d2fSChristopher Di Bella static_assert(!std::regular<has_rvalue_reference_member>);
14024dd2d2fSChristopher Di Bella static_assert(!std::regular<has_function_ref_member>);
14124dd2d2fSChristopher Di Bella static_assert(!std::regular<deleted_assignment_from_const_rvalue>);
14224dd2d2fSChristopher Di Bella 
14324dd2d2fSChristopher Di Bella // not default_initializable
14424dd2d2fSChristopher Di Bella static_assert(!std::regular<std::runtime_error>);
14524dd2d2fSChristopher Di Bella static_assert(
14624dd2d2fSChristopher Di Bella     !std::regular<std::tuple<std::runtime_error, std::overflow_error> >);
14724dd2d2fSChristopher Di Bella static_assert(!std::regular<std::nullopt_t>);
14824dd2d2fSChristopher Di Bella static_assert(!std::regular<no_copy_constructor>);
14924dd2d2fSChristopher Di Bella static_assert(!std::regular<no_copy_assignment>);
15024dd2d2fSChristopher Di Bella static_assert(std::is_copy_assignable_v<no_copy_assignment_mutable> &&
15124dd2d2fSChristopher Di Bella               !std::regular<no_copy_assignment_mutable>);
15224dd2d2fSChristopher Di Bella static_assert(!std::regular<derived_from_noncopyable>);
15324dd2d2fSChristopher Di Bella static_assert(!std::regular<has_noncopyable>);
15424dd2d2fSChristopher Di Bella 
15524dd2d2fSChristopher Di Bella static_assert(!std::regular<derived_from_non_default_initializable>);
15624dd2d2fSChristopher Di Bella static_assert(!std::regular<has_non_default_initializable>);
15724dd2d2fSChristopher Di Bella 
15824dd2d2fSChristopher Di Bella // not equality_comparable
15924dd2d2fSChristopher Di Bella static_assert(!std::regular<const_copy_assignment const>);
16024dd2d2fSChristopher Di Bella static_assert(!std::regular<cv_copy_assignment const volatile>);
16124dd2d2fSChristopher Di Bella 
16224dd2d2fSChristopher Di Bella struct is_equality_comparable {
163*88b73a98SLouis Dionne   bool operator==(is_equality_comparable const&) const = default;
16424dd2d2fSChristopher Di Bella };
16524dd2d2fSChristopher Di Bella static_assert(std::regular<is_equality_comparable>);
166