xref: /llvm-project/libcxx/test/std/concepts/concepts.object/movable.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 movable = 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 <optional>
2124dd2d2fSChristopher Di Bella #include <unordered_map>
2224dd2d2fSChristopher Di Bella #include <vector>
2324dd2d2fSChristopher Di Bella 
2484bb1459SMark de Wever #include "test_macros.h"
2584bb1459SMark de Wever 
2684bb1459SMark de Wever #ifndef TEST_HAS_NO_THREADS
27e1ce3dabSLouis Dionne #  include <mutex>
28e1ce3dabSLouis Dionne #endif
29e1ce3dabSLouis Dionne 
3024dd2d2fSChristopher Di Bella #include "type_classification/moveconstructible.h"
3124dd2d2fSChristopher Di Bella #include "type_classification/movable.h"
3224dd2d2fSChristopher Di Bella 
3324dd2d2fSChristopher Di Bella // Movable types
3424dd2d2fSChristopher Di Bella static_assert(std::movable<int>);
3524dd2d2fSChristopher Di Bella static_assert(std::movable<int volatile>);
3624dd2d2fSChristopher Di Bella static_assert(std::movable<int*>);
3724dd2d2fSChristopher Di Bella static_assert(std::movable<int const*>);
3824dd2d2fSChristopher Di Bella static_assert(std::movable<int volatile*>);
3924dd2d2fSChristopher Di Bella static_assert(std::movable<int const volatile*>);
4024dd2d2fSChristopher Di Bella static_assert(std::movable<int (*)()>);
4124dd2d2fSChristopher Di Bella 
4224dd2d2fSChristopher Di Bella struct S {};
4324dd2d2fSChristopher Di Bella static_assert(std::movable<S>);
4424dd2d2fSChristopher Di Bella static_assert(std::movable<int S::*>);
4524dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)()>);
4624dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() noexcept>);
4724dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() &>);
4824dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() & noexcept>);
4924dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() &&>);
5024dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() && noexcept>);
5124dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const>);
5224dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const noexcept>);
5324dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const&>);
5424dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const & noexcept>);
5524dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const&&>);
5624dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const && noexcept>);
5724dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile>);
5824dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile noexcept>);
5924dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile&>);
6024dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile & noexcept>);
6124dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile&&>);
6224dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() volatile && noexcept>);
6324dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile>);
6424dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile noexcept>);
6524dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile&>);
6624dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile & noexcept>);
6724dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile&&>);
6824dd2d2fSChristopher Di Bella static_assert(std::movable<int (S::*)() const volatile && noexcept>);
6924dd2d2fSChristopher Di Bella 
7024dd2d2fSChristopher Di Bella static_assert(std::movable<std::deque<int> >);
7124dd2d2fSChristopher Di Bella static_assert(std::movable<std::forward_list<int> >);
7224dd2d2fSChristopher Di Bella static_assert(std::movable<std::list<int> >);
7324dd2d2fSChristopher Di Bella static_assert(std::movable<std::optional<std::vector<int> > >);
7424dd2d2fSChristopher Di Bella static_assert(std::movable<std::vector<int> >);
7524dd2d2fSChristopher Di Bella 
7624dd2d2fSChristopher Di Bella static_assert(std::movable<has_volatile_member>);
7724dd2d2fSChristopher Di Bella static_assert(std::movable<has_array_member>);
7824dd2d2fSChristopher Di Bella 
7924dd2d2fSChristopher Di Bella // Not objects
8024dd2d2fSChristopher Di Bella static_assert(!std::movable<int&>);
8124dd2d2fSChristopher Di Bella static_assert(!std::movable<int const&>);
8224dd2d2fSChristopher Di Bella static_assert(!std::movable<int volatile&>);
8324dd2d2fSChristopher Di Bella static_assert(!std::movable<int const volatile&>);
8424dd2d2fSChristopher Di Bella static_assert(!std::movable<int&&>);
8524dd2d2fSChristopher Di Bella static_assert(!std::movable<int const&&>);
8624dd2d2fSChristopher Di Bella static_assert(!std::movable<int volatile&&>);
8724dd2d2fSChristopher Di Bella static_assert(!std::movable<int const volatile&&>);
8824dd2d2fSChristopher Di Bella static_assert(!std::movable<int()>);
8924dd2d2fSChristopher Di Bella static_assert(!std::movable<int (&)()>);
9024dd2d2fSChristopher Di Bella static_assert(!std::movable<int[5]>);
9124dd2d2fSChristopher Di Bella 
9224dd2d2fSChristopher Di Bella // Core non-move assignable.
9324dd2d2fSChristopher Di Bella static_assert(!std::movable<int const>);
9424dd2d2fSChristopher Di Bella static_assert(!std::movable<int const volatile>);
9524dd2d2fSChristopher Di Bella 
9624dd2d2fSChristopher Di Bella static_assert(!std::movable<DeletedMoveCtor>);
9724dd2d2fSChristopher Di Bella static_assert(!std::movable<ImplicitlyDeletedMoveCtor>);
9824dd2d2fSChristopher Di Bella static_assert(!std::movable<DeletedMoveAssign>);
9924dd2d2fSChristopher Di Bella static_assert(!std::movable<ImplicitlyDeletedMoveAssign>);
10024dd2d2fSChristopher Di Bella static_assert(!std::movable<NonMovable>);
10124dd2d2fSChristopher Di Bella static_assert(!std::movable<DerivedFromNonMovable>);
10224dd2d2fSChristopher Di Bella static_assert(!std::movable<HasANonMovable>);
10324dd2d2fSChristopher Di Bella 
10424dd2d2fSChristopher Di Bella static_assert(std::movable<cpp03_friendly>);
10524dd2d2fSChristopher Di Bella static_assert(std::movable<const_move_ctor>);
10624dd2d2fSChristopher Di Bella static_assert(std::movable<volatile_move_ctor>);
10724dd2d2fSChristopher Di Bella static_assert(std::movable<cv_move_ctor>);
10824dd2d2fSChristopher Di Bella static_assert(std::movable<multi_param_move_ctor>);
10924dd2d2fSChristopher Di Bella static_assert(!std::movable<not_quite_multi_param_move_ctor>);
11024dd2d2fSChristopher Di Bella 
111*e39095a3SLouis Dionne static_assert(!std::assignable_from<copy_with_mutable_parameter&,
112*e39095a3SLouis Dionne                                     copy_with_mutable_parameter>);
113*e39095a3SLouis Dionne static_assert(!std::movable<copy_with_mutable_parameter>);
11424dd2d2fSChristopher Di Bella 
11524dd2d2fSChristopher Di Bella static_assert(!std::movable<const_move_assignment>);
11624dd2d2fSChristopher Di Bella static_assert(std::movable<volatile_move_assignment>);
11724dd2d2fSChristopher Di Bella static_assert(!std::movable<cv_move_assignment>);
11824dd2d2fSChristopher Di Bella 
11924dd2d2fSChristopher Di Bella static_assert(!std::movable<const_move_assign_and_traditional_move_assign>);
12024dd2d2fSChristopher Di Bella static_assert(!std::movable<volatile_move_assign_and_traditional_move_assign>);
12124dd2d2fSChristopher Di Bella static_assert(!std::movable<cv_move_assign_and_traditional_move_assign>);
12224dd2d2fSChristopher Di Bella static_assert(std::movable<const_move_assign_and_default_ops>);
12324dd2d2fSChristopher Di Bella static_assert(std::movable<volatile_move_assign_and_default_ops>);
12424dd2d2fSChristopher Di Bella static_assert(std::movable<cv_move_assign_and_default_ops>);
12524dd2d2fSChristopher Di Bella 
12624dd2d2fSChristopher Di Bella static_assert(!std::movable<has_const_member>);
12724dd2d2fSChristopher Di Bella static_assert(!std::movable<has_cv_member>);
12824dd2d2fSChristopher Di Bella static_assert(!std::movable<has_lvalue_reference_member>);
12924dd2d2fSChristopher Di Bella static_assert(!std::movable<has_rvalue_reference_member>);
13024dd2d2fSChristopher Di Bella static_assert(!std::movable<has_function_ref_member>);
13124dd2d2fSChristopher Di Bella 
13224dd2d2fSChristopher Di Bella static_assert(std::movable<deleted_assignment_from_const_rvalue>);
13324dd2d2fSChristopher Di Bella 
13424dd2d2fSChristopher Di Bella // `move_constructible and assignable_from<T&, T>` implies `swappable<T>`,
13524dd2d2fSChristopher Di Bella // so there's nothing to test for the case of non-swappable.
136