File: array_resize.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (46 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download | duplicates (3)
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
// name: array_resize.ck
// desc: this demonstrates how array resize and clear;
//       also see: array_capacity.ck
//       modified: 1.4.1.0 (ge)
//
//       (NOTE: .capacity() is not the same as .cap(); the latter is
//       maintained for historical / compatibility reasons; .cap()
//       actually is the same as .size() -- which is rather confusing!
//
//       It is strongly recommended that .cap() be avoided; instead,
//       explicitly use .size() or .capacity() as appropriate.)

// instantiate a float array
float argh[0];

// print
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>;

// resize
4 => argh.size;

// print
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>;

// set elements
3.0 => argh[0];
4 => argh[1];
5.0 => argh[2];
6 => argh[3];

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

// recap
2 => argh.size;

// print
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>;

// clear the contents
argh.clear();

// print
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>;