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 // <string>
10
11 // allocator_type get_allocator() const; // constexpr since C++20
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19
20 template <class S>
21 TEST_CONSTEXPR_CXX20 void
test(const S & s,const typename S::allocator_type & a)22 test(const S& s, const typename S::allocator_type& a)
23 {
24 assert(s.get_allocator() == a);
25 }
26
test()27 TEST_CONSTEXPR_CXX20 bool test() {
28 {
29 typedef test_allocator<char> A;
30 typedef std::basic_string<char, std::char_traits<char>, A> S;
31 test(S(""), A());
32 test(S("abcde", A(1)), A(1));
33 test(S("abcdefghij", A(2)), A(2));
34 test(S("abcdefghijklmnopqrst", A(3)), A(3));
35 }
36 #if TEST_STD_VER >= 11
37 {
38 typedef min_allocator<char> A;
39 typedef std::basic_string<char, std::char_traits<char>, A> S;
40 test(S(""), A());
41 test(S("abcde", A()), A());
42 test(S("abcdefghij", A()), A());
43 test(S("abcdefghijklmnopqrst", A()), A());
44 }
45 #endif
46
47 return true;
48 }
49
main(int,char **)50 int main(int, char**)
51 {
52 test();
53 #if TEST_STD_VER > 17
54 static_assert(test());
55 #endif
56
57 return 0;
58 }
59