1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <list>
10
11// list& operator=(list&& c)
12// noexcept(
13// allocator_type::propagate_on_container_move_assignment::value &&
14// is_nothrow_move_assignable<allocator_type>::value);
15
16// This tests a conforming extension
17
18// UNSUPPORTED: c++03
19
20#include <list>
21
22#include "test_macros.h"
23#include "MoveOnly.h"
24#include "test_allocator.h"
25
26template <class T>
27struct always_equal_alloc {
28 using value_type = T;
29 always_equal_alloc(const always_equal_alloc&);
30 void allocate(std::size_t);
31};
32
33template <class T>
34struct not_always_equal_alloc {
35 int i;
36 using value_type = T;
37 not_always_equal_alloc(const not_always_equal_alloc&);
38 void allocate(std::size_t);
39};
40
41static_assert(std::is_nothrow_move_assignable<std::list<MoveOnly>>::value, "");
42static_assert(!std::is_nothrow_move_assignable<std::list<MoveOnly, test_allocator<MoveOnly>>>::value, "");
43#if TEST_STD_VER >= 17
44static_assert(std::is_nothrow_move_assignable<std::list<MoveOnly, always_equal_alloc<MoveOnly>>>::value, "");
45#endif
46static_assert(!std::is_nothrow_move_assignable<std::list<MoveOnly, not_always_equal_alloc<MoveOnly>>>::value, "");
47#if defined(_LIBCPP_VERSION)
48static_assert(std::is_nothrow_move_assignable<std::list<MoveOnly, other_allocator<MoveOnly>>>::value, "");
49#endif // _LIBCPP_VERSION
50

source code of libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.compile.pass.cpp