| 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 |
#include <cassert> |
| 12 |
#include <string> |
| 13 |
|
| 14 |
#include "test_macros.h" |
| 15 |
|
| 16 |
struct Incomplete; |
| 17 |
template <class T> |
| 18 |
struct Holder { |
| 19 |
T t; |
| 20 |
}; |
| 21 |
|
| 22 |
template <class T> |
| 23 |
struct Charlike { |
| 24 |
char ch_; |
| 25 |
TEST_CONSTEXPR Charlike(char ch) : ch_(ch) {} |
| 26 |
TEST_CONSTEXPR operator char() const { return ch_; } |
| 27 |
}; |
| 28 |
|
| 29 |
template <class S> |
| 30 |
TEST_CONSTEXPR_CXX20 void test_string() { |
| 31 |
S s; |
| 32 |
Charlike<Holder<Incomplete> > a[] = {'m', 'a', 'h', 'i'}; |
| 33 |
s.append(a, a + 4); |
| 34 |
s.assign(a, a + 4); |
| 35 |
s.insert(s.begin(), a, a + 4); |
| 36 |
s.replace(s.begin(), s.begin() + 4, a, a + 4); |
| 37 |
assert(s == "mahimahi"); |
| 38 |
} |
| 39 |
|
| 40 |
TEST_CONSTEXPR_CXX20 bool test() { |
| 41 |
test_string<std::string>(); |
| 42 |
|
| 43 |
return true; |
| 44 |
} |
| 45 |
|
| 46 |
int main(int, char**) { |
| 47 |
test(); |
| 48 |
#if TEST_STD_VER > 17 |
| 49 |
static_assert(test()); |
| 50 |
#endif |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |