xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp (revision d04c6851681bc9b89ba98c1644cd62d7fb719ac2)
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <vector>
11 
12 // vector& operator=(vector&& c)
13 //     noexcept(
14 //          allocator_type::propagate_on_container_move_assignment::value &&
15 //          is_nothrow_move_assignable<allocator_type>::value);
16 
17 // This tests a conforming extension
18 
19 #include <vector>
20 #include <cassert>
21 
22 #include "test_allocator.h"
23 
24 template <class T>
25 struct some_alloc
26 {
27     typedef T value_type;
28     some_alloc(const some_alloc&);
29 };
30 
31 template <class T>
32 struct some_alloc2
33 {
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 
44 template <class T>
45 struct some_alloc3
46 {
47     typedef T value_type;
48 
49     some_alloc3() {}
50     some_alloc3(const some_alloc3&);
51     void deallocate(void*, unsigned) {}
52 
53     typedef std::false_type propagate_on_container_move_assignment;
54     typedef std::false_type is_always_equal;
55 };
56 
57 int main()
58 {
59 #if __has_feature(cxx_noexcept)
60     {
61         typedef std::vector<bool> C;
62         static_assert(std::is_nothrow_move_assignable<C>::value, "");
63     }
64     {
65         typedef std::vector<bool, test_allocator<bool>> C;
66         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
67     }
68     {
69         typedef std::vector<bool, other_allocator<bool>> C;
70         static_assert(std::is_nothrow_move_assignable<C>::value, "");
71     }
72     {
73         typedef std::vector<bool, some_alloc<bool>> C;
74 #if TEST_STD_VER > 14
75         static_assert( std::is_nothrow_move_assignable<C>::value, "");
76 #else
77         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
78 #endif
79     }
80 #if TEST_STD_VER > 14
81     {  // POCMA false, is_always_equal true
82         typedef std::vector<bool, some_alloc2<bool>> C;
83         static_assert( std::is_nothrow_move_assignable<C>::value, "");
84     }
85     {  // POCMA false, is_always_equal false
86         typedef std::vector<bool, some_alloc3<bool>> C;
87         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
88     }
89 #endif
90 
91 #endif
92 }
93