File: array_erase2.ck

package info (click to toggle)
chuck 1.5.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 41,260 kB
  • sloc: cpp: 124,539; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (30 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (6)
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
// name: array_erase2.ck
// desc: shows array.erase(int, int) to remove a range
//
// requires: chuck-1.5.0.8 or higher

// create zero-length array
int a[0];

// print size
<<< "size (before append):", a.size() >>>;

// append
a << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8;

// print size
<<< "size (after append):", a.size() >>>;

// erase 3rd to 5th element
// NOTE erase(begin, end) remove [begin,end):
// i.e., starting with begin and up to but NOT including end
a.erase( 2, 5 );

// print size
<<< "size (after erase and popFront):", a.size() >>>;

// print contents
for( int i; i < a.size(); i++ )
{
    <<< i, ":", a[i] >>>;
}