| 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 |
assert(s.get_allocator() == a); |
| 23 |
} |
| 24 |
|
| 25 |
template <class Alloc> |
| 26 |
TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) { |
| 27 |
using S = std::basic_string<char, std::char_traits<char>, Alloc>; |
| 28 |
test(S(""), Alloc()); |
| 29 |
test(S("abcde", Alloc(a)), Alloc(a)); |
| 30 |
test(S("abcdefghij", Alloc(a)), Alloc(a)); |
| 31 |
test(S("abcdefghijklmnopqrst", Alloc(a)), Alloc(a)); |
| 32 |
} |
| 33 |
|
| 34 |
TEST_CONSTEXPR_CXX20 bool test() { |
| 35 |
test_string(std::allocator<char>()); |
| 36 |
test_string(test_allocator<char>()); |
| 37 |
test_string(test_allocator<char>(1)); |
| 38 |
test_string(test_allocator<char>(2)); |
| 39 |
test_string(test_allocator<char>(3)); |
| 40 |
#if TEST_STD_VER >= 11 |
| 41 |
test_string(min_allocator<char>()); |
| 42 |
#endif |
| 43 |
|
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
int main(int, char**) { |
| 48 |
test(); |
| 49 |
#if TEST_STD_VER > 17 |
| 50 |
static_assert(test()); |
| 51 |
#endif |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |