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// <vector>
10
11// vector& operator=(vector&& 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 <vector>
21#include <cassert>
22
23#include "test_macros.h"
24#include "MoveOnly.h"
25#include "test_allocator.h"
26
27template <class T>
28struct some_alloc {
29 typedef T value_type;
30 some_alloc(const some_alloc&);
31 void allocate(std::size_t);
32};
33
34template <class T>
35struct some_alloc2 {
36 typedef T value_type;
37
38 some_alloc2() {}
39 some_alloc2(const some_alloc2&);
40 void allocate(std::size_t);
41 void deallocate(void*, unsigned) {}
42
43 typedef std::false_type propagate_on_container_move_assignment;
44 typedef std::true_type is_always_equal;
45};
46
47template <class T>
48struct some_alloc3 {
49 typedef T value_type;
50
51 some_alloc3() {}
52 some_alloc3(const some_alloc3&);
53 void allocate(std::size_t);
54 void deallocate(void*, unsigned) {}
55
56 typedef std::false_type propagate_on_container_move_assignment;
57 typedef std::false_type is_always_equal;
58};
59
60int main(int, char**) {
61 {
62 typedef std::vector<MoveOnly> C;
63 static_assert(std::is_nothrow_move_assignable<C>::value, "");
64 }
65 {
66 typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
67 static_assert(!std::is_nothrow_move_assignable<C>::value, "");
68 }
69 {
70 typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
71 static_assert(std::is_nothrow_move_assignable<C>::value, "");
72 }
73 {
74 typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
75 // In C++17, move assignment for allocators are not allowed to throw
76#if TEST_STD_VER > 14
77 static_assert(std::is_nothrow_move_assignable<C>::value, "");
78#else
79 static_assert(!std::is_nothrow_move_assignable<C>::value, "");
80#endif
81 }
82
83#if TEST_STD_VER > 14
84 { // POCMA false, is_always_equal true
85 typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C;
86 static_assert(std::is_nothrow_move_assignable<C>::value, "");
87 }
88 { // POCMA false, is_always_equal false
89 typedef std::vector<MoveOnly, some_alloc3<MoveOnly>> C;
90 static_assert(!std::is_nothrow_move_assignable<C>::value, "");
91 }
92#endif
93
94 return 0;
95}
96

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