xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp (revision f2f2a6395fad5bd49a573fdf2b20072735d496f7)
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 // UNSUPPORTED: c++98, c++03
20 
21 #include <vector>
22 #include <cassert>
23 
24 #include "test_allocator.h"
25 
26 template <class T>
27 struct some_alloc
28 {
29     typedef T value_type;
30     some_alloc(const some_alloc&);
31 };
32 
33 template <class T>
34 struct some_alloc2
35 {
36     typedef T value_type;
37 
38     some_alloc2() {}
39     some_alloc2(const some_alloc2&);
40     void deallocate(void*, unsigned) {}
41 
42     typedef std::false_type propagate_on_container_move_assignment;
43     typedef std::true_type is_always_equal;
44 };
45 
46 template <class T>
47 struct some_alloc3
48 {
49     typedef T value_type;
50 
51     some_alloc3() {}
52     some_alloc3(const some_alloc3&);
53     void deallocate(void*, unsigned) {}
54 
55     typedef std::false_type propagate_on_container_move_assignment;
56     typedef std::false_type is_always_equal;
57 };
58 
59 int main()
60 {
61     {
62         typedef std::vector<bool> C;
63         static_assert(std::is_nothrow_move_assignable<C>::value, "");
64     }
65     {
66         typedef std::vector<bool, test_allocator<bool>> C;
67         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
68     }
69     {
70         typedef std::vector<bool, other_allocator<bool>> C;
71         static_assert(std::is_nothrow_move_assignable<C>::value, "");
72     }
73     {
74         typedef std::vector<bool, some_alloc<bool>> C;
75 #if TEST_STD_VER > 14
76         static_assert( std::is_nothrow_move_assignable<C>::value, "");
77 #else
78         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
79 #endif
80     }
81 #if TEST_STD_VER > 14
82     {  // POCMA false, is_always_equal true
83         typedef std::vector<bool, some_alloc2<bool>> C;
84         static_assert( std::is_nothrow_move_assignable<C>::value, "");
85     }
86     {  // POCMA false, is_always_equal false
87         typedef std::vector<bool, some_alloc3<bool>> C;
88         static_assert(!std::is_nothrow_move_assignable<C>::value, "");
89     }
90 #endif
91 }
92