| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
// { dg-require-effective-target cxx11_abi } |
| 3 |
|
| 4 |
#include <string> |
| 5 |
#include <testsuite_hooks.h> |
| 6 |
|
| 7 |
constexpr bool |
| 8 |
test_insert() |
| 9 |
{ |
| 10 |
std::string s; |
| 11 |
s.insert(0, "one"); |
| 12 |
VERIFY( s == "one" ); |
| 13 |
s.insert(0, "eleventy-"); |
| 14 |
VERIFY( s == "eleventy-one" ); |
| 15 |
s.insert(6, "ses at ten thirteen", 15); |
| 16 |
VERIFY( s == "elevenses at ten thirty-one" ); |
| 17 |
|
| 18 |
return true; |
| 19 |
} |
| 20 |
|
| 21 |
static_assert( test_insert() ); |
| 22 |
|
| 23 |
constexpr bool |
| 24 |
test_replace() |
| 25 |
{ |
| 26 |
std::string s = "abcdef"; |
| 27 |
s.replace(2, 1, s.c_str(), 3); |
| 28 |
VERIFY( s == "ababcdef" ); |
| 29 |
s.replace(0, 2, "", 0); |
| 30 |
VERIFY( s == "abcdef" ); |
| 31 |
s.replace(1, 4, "ardwol", 6); |
| 32 |
VERIFY( s == "aardwolf" ); |
| 33 |
s.replace(4, 0, "vark not wolf"); |
| 34 |
|
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
static_assert( test_replace() ); |
| 39 |
|
| 40 |
constexpr bool |
| 41 |
test_erasure() |
| 42 |
{ |
| 43 |
std::string s = "Spiritualized Electric Mainline"; |
| 44 |
std::erase(s, 'i'); |
| 45 |
VERIFY( s == "Sprtualzed Electrc Manlne" ); |
| 46 |
std::erase_if(s, [](char c) { return c == 'l'; }); |
| 47 |
VERIFY( s == "Sprtuazed Eectrc Manne" ); |
| 48 |
|
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
static_assert( test_erasure() ); |
| 53 |
|
| 54 |
constexpr bool |
| 55 |
test_move() |
| 56 |
{ |
| 57 |
// PR libstdc++/113294 |
| 58 |
std::string s1; |
| 59 |
std::string s2 = "1234567890123456"; // 16 chars: more than _S_local_capacity |
| 60 |
s1 = std::move(s2); |
| 61 |
VERIFY( s1 == "1234567890123456" ); |
| 62 |
|
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
static_assert( test_move() ); |