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 // <string>
11
12 // explicit basic_string(const Allocator& a = Allocator());
13
14 #include <string>
15 #include <cassert>
16
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20
21 template <class S>
22 void
test()23 test()
24 {
25 {
26 #if TEST_STD_VER > 14
27 static_assert((noexcept(S{})), "" );
28 #elif TEST_STD_VER >= 11
29 static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
30 #endif
31 S s;
32 LIBCPP_ASSERT(s.__invariants());
33 assert(s.data());
34 assert(s.size() == 0);
35 assert(s.capacity() >= s.size());
36 assert(s.get_allocator() == typename S::allocator_type());
37 }
38 {
39 #if TEST_STD_VER > 14
40 static_assert((noexcept(S{typename S::allocator_type{}})), "" );
41 #elif TEST_STD_VER >= 11
42 static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
43 #endif
44 S s(typename S::allocator_type(5));
45 LIBCPP_ASSERT(s.__invariants());
46 assert(s.data());
47 assert(s.size() == 0);
48 assert(s.capacity() >= s.size());
49 assert(s.get_allocator() == typename S::allocator_type(5));
50 }
51 }
52
53 #if TEST_STD_VER >= 11
54
55 template <class S>
56 void
test2()57 test2()
58 {
59 {
60 #if TEST_STD_VER > 14
61 static_assert((noexcept(S{})), "" );
62 #elif TEST_STD_VER >= 11
63 static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
64 #endif
65 S s;
66 LIBCPP_ASSERT(s.__invariants());
67 assert(s.data());
68 assert(s.size() == 0);
69 assert(s.capacity() >= s.size());
70 assert(s.get_allocator() == typename S::allocator_type());
71 }
72 {
73 #if TEST_STD_VER > 14
74 static_assert((noexcept(S{typename S::allocator_type{}})), "" );
75 #elif TEST_STD_VER >= 11
76 static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
77 #endif
78 S s(typename S::allocator_type{});
79 LIBCPP_ASSERT(s.__invariants());
80 assert(s.data());
81 assert(s.size() == 0);
82 assert(s.capacity() >= s.size());
83 assert(s.get_allocator() == typename S::allocator_type());
84 }
85 }
86
87 #endif
88
main()89 int main()
90 {
91 test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
92 #if TEST_STD_VER >= 11
93 test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
94 test2<std::basic_string<char, std::char_traits<char>, explicit_allocator<char> > >();
95 #endif
96 }
97