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