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

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