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