File: 2.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (112 lines) | stat: -rw-r--r-- 2,805 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// { dg-do run { target c++23 } }

#include <spanstream>
#include <testsuite_hooks.h>

using std::ispanstream;
using std::ospanstream;
using std::span;

void
test_move()
{
  char c;
  {
    const char str[] = "chars";
    std::ispanstream a(str);
    std::ispanstream b = std::move(a);
    VERIFY( b.span().data() == str && b.span().size() == 6 );
    VERIFY( b >> c );
    VERIFY( c == 'c' );

    a = std::move(b);
    VERIFY( a.span().data() == str && a.span().size() == 6 );
    VERIFY( a >> c >> c );
    VERIFY( c == 'a' );
  }

  {
    char buf[10] = {};
    std::ospanstream a(buf);
    std::ospanstream b = std::move(a);
    VERIFY( b << 'c' );
    VERIFY( buf[0] == 'c' );
    VERIFY( !std::char_traits<char>::compare(buf, "c", 2) );

    a = std::move(b);
    VERIFY( a << 'h' << 'a' << "rs" );
    VERIFY( !std::char_traits<char>::compare(buf, "chars", 6) );
  }

  {
    char buf[10] = {};
    std::spanstream a(buf);
    std::spanstream b = std::move(a);
    VERIFY( b.span().empty() );
    VERIFY( b << 'c' );
    VERIFY( buf[0] == 'c' );
    VERIFY( !std::char_traits<char>::compare(buf, "c", 2) );
    VERIFY( b.span().data() == buf && b.span().size() == 1 );
    VERIFY( b >> c );
    VERIFY( c == 'c' );

    a = std::move(b);
    VERIFY( a.span().data() == buf && a.span().size() == 1 );
    VERIFY( a << 'h' << 'a' << "rs" );
    VERIFY( !std::char_traits<char>::compare(buf, "chars", 6) );
    VERIFY( a.span().data() == buf && a.span().size() == 5 );
  }
}

void
test_swap()
{
  {
    const char str1[] = "chars";
    const char str2[] = "STRING";
    std::ispanstream a(str1);
    std::ispanstream b(str2);
    a.swap(b);
    VERIFY( a.span().data() == str2 && a.span().size() == 7 );
    VERIFY( b.span().data() == str1 && b.span().size() == 6 );
    char c;
    VERIFY( a >> c );
    VERIFY( c == 'S' );
    VERIFY( b >> c );
    VERIFY( c == 'c' );

    swap(a, b);
    VERIFY( a.span().data() == str1 && a.span().size() == 6 );
    VERIFY( b.span().data() == str2 && b.span().size() == 7 );
    VERIFY( a >> c >> c );
    VERIFY( c == 'a' );
    VERIFY( b >> c >> c );
    VERIFY( c == 'R' );
  }

  {
    char buf1[] = "xxxxxxxxxxxxxxx";
    char buf2[] = "xxxxxxxxxxxxxxx";
    std::ospanstream a(buf1);
    std::ospanstream b(buf2);
    a.swap(b);
    VERIFY( a << "STR" );
    VERIFY( !std::char_traits<char>::compare(buf2, "STRx", 4) );
    VERIFY( b << 'c' << 'h' );
    VERIFY( !std::char_traits<char>::compare(buf1, "chx", 3) );

    swap(a, b);
    VERIFY( a.span().size() == 2 );
    VERIFY( b.span().size() == 3 );
    VERIFY( a << 'a' << "rs" );
    VERIFY( !std::char_traits<char>::compare(buf1, "charsx", 6) );
    VERIFY( b << "IN" << 'G' );
    VERIFY( !std::char_traits<char>::compare(buf2, "STRINGx", 7) );
  }
}

int main()
{
  test_move();
  test_swap();
}