summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc
blob: d7022af3cabe981fbc0d682fd893c5e2e578ec7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// { dg-do compile { target c++20 } }
// { dg-require-effective-target cxx11_abi }

#include <string>
#include <testsuite_hooks.h>

constexpr bool
test_insert()
{
  std::string s;
  s.insert(0, "one");
  VERIFY( s == "one" );
  s.insert(0, "eleventy-");
  VERIFY( s == "eleventy-one" );
  s.insert(6, "ses at ten thirteen", 15);
  VERIFY( s == "elevenses at ten thirty-one" );

  return true;
}

static_assert( test_insert() );

constexpr bool
test_replace()
{
  std::string s = "abcdef";
  s.replace(2, 1, s.c_str(), 3);
  VERIFY( s == "ababcdef" );
  s.replace(0, 2, "", 0);
  VERIFY( s == "abcdef" );
  s.replace(1, 4, "ardwol", 6);
  VERIFY( s == "aardwolf" );
  s.replace(4, 0, "vark not wolf");

  return true;
}

static_assert( test_replace() );

constexpr bool
test_erasure()
{
  std::string s = "Spiritualized Electric Mainline";
  std::erase(s, 'i');
  VERIFY( s == "Sprtualzed Electrc Manlne" );
  std::erase_if(s, [](char c) { return c == 'l'; });
  VERIFY( s == "Sprtuazed Eectrc Manne" );

  return true;
}

static_assert( test_erasure() );

constexpr bool
test_move()
{
  // PR libstdc++/113294
  std::string s1;
  std::string s2 = "1234567890123456"; // 16 chars: more than _S_local_capacity
  s1 = std::move(s2);
  VERIFY( s1 == "1234567890123456" );

  return true;
}

static_assert( test_move() );