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 // UNSUPPORTED: c++98, c++03, c++11
11 // <vector>
12 //  vector.bool
13 
14 // template <class... Args> reference emplace_back(Args&&... args);
15 // return type is 'reference' in C++17; 'void' before
16 
17 #include <vector>
18 #include <cassert>
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 
main()22 int main()
23 {
24     {
25         typedef std::vector<bool> C;
26         C c;
27 #if TEST_STD_VER > 14
28         typedef C::reference Ref;
29         Ref r1 = c.emplace_back();
30         assert(c.size() == 1);
31         assert(c.front() == false);
32         r1 = true;
33         assert(c.front() == true);
34         r1 = false;
35         Ref r2 = c.emplace_back(true);
36         assert(c.size() == 2);
37         assert(c.front() == false);
38         assert(c.back() == true);
39         r2 = false;
40         assert(c.back() == false);
41         r2 = true;
42 #else
43         c.emplace_back();
44         assert(c.size() == 1);
45         assert(c.front() == false);
46         c.emplace_back(true);
47         assert(c.size() == 2);
48         assert(c.front() == false);
49         assert(c.back() == true);
50 #endif
51         c.emplace_back(true);
52         assert(c.size() == 3);
53         assert(c.front() == false);
54         assert(c[1] == true);
55         assert(c.back() == true);
56     }
57     {
58         typedef std::vector<bool, min_allocator<bool>> C;
59         C c;
60 
61 #if TEST_STD_VER > 14
62         typedef C::reference Ref;
63         Ref r1 = c.emplace_back();
64         assert(c.size() == 1);
65         assert(c.front() == false);
66         r1 = true;
67         assert(c.front() == true);
68         r1 = false;
69         Ref r2 = c.emplace_back(true);
70         assert(c.size() == 2);
71         assert(c.front() == false);
72         assert(c.back() == true);
73         r2 = false;
74         assert(c.back() == false);
75         r2 = true;
76 #else
77         c.emplace_back();
78         assert(c.size() == 1);
79         assert(c.front() == false);
80         c.emplace_back(true);
81         assert(c.size() == 2);
82         assert(c.front() == false);
83         assert(c.back() == true);
84 #endif
85         c.emplace_back(true);
86         assert(c.size() == 3);
87         assert(c.front() == false);
88         assert(c[1] == true);
89         assert(c.back() == true);
90     }
91 }
92