Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.ops / string.accessors / get_allocator.pass.cpp
bloba6158aeb38dc2e8daa51d9fbf0adce0aa2947e67
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 //===----------------------------------------------------------------------===//
9 // <string>
11 // allocator_type get_allocator() const; // constexpr since C++20
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
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);
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));
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
44 return true;
47 int main(int, char**) {
48 test();
49 #if TEST_STD_VER > 17
50 static_assert(test());
51 #endif
53 return 0;