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<bool>
10
11 // vector();
12 // vector(const Alloc&);
13
14 // This tests a conforming extension
15 // For vector<>, this was added to the standard by N4258,
16 // but vector<bool> was not changed.
17
18
19 #include <vector>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
25
26 template <class C>
27 void
test0()28 test0()
29 {
30 #if TEST_STD_VER > 14
31 LIBCPP_STATIC_ASSERT((noexcept(C{})), "" );
32 #elif TEST_STD_VER >= 11
33 LIBCPP_STATIC_ASSERT((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
34 #endif
35 C c;
36 LIBCPP_ASSERT(c.__invariants());
37 assert(c.empty());
38 assert(c.get_allocator() == typename C::allocator_type());
39 #if TEST_STD_VER >= 11
40 C c1 = {};
41 LIBCPP_ASSERT(c1.__invariants());
42 assert(c1.empty());
43 assert(c1.get_allocator() == typename C::allocator_type());
44 #endif
45 }
46
47 template <class C>
48 void
test1(const typename C::allocator_type & a)49 test1(const typename C::allocator_type& a)
50 {
51 #if TEST_STD_VER > 14
52 LIBCPP_STATIC_ASSERT((noexcept(C{typename C::allocator_type{}})), "" );
53 #elif TEST_STD_VER >= 11
54 LIBCPP_STATIC_ASSERT((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
55 #endif
56 C c(a);
57 LIBCPP_ASSERT(c.__invariants());
58 assert(c.empty());
59 assert(c.get_allocator() == a);
60 }
61
main(int,char **)62 int main(int, char**)
63 {
64 {
65 test0<std::vector<bool> >();
66 test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
67 }
68 #if TEST_STD_VER >= 11
69 {
70 test0<std::vector<bool, min_allocator<bool>> >();
71 test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
72 }
73 {
74 test0<std::vector<bool, explicit_allocator<bool>> >();
75 test1<std::vector<bool, explicit_allocator<bool> > >(explicit_allocator<bool>());
76 }
77 #endif
78
79 return 0;
80 }
81