| 1 |
// name: array_resize.ck |
| 2 |
// desc: this demonstrates how array resize and clear; |
| 3 |
// also see: array_capacity.ck |
| 4 |
// modified: 1.4.1.0 (ge) |
| 5 |
// |
| 6 |
// (NOTE: .capacity() is not the same as .cap(); the latter is |
| 7 |
// maintained for historical / compatibility reasons; .cap() |
| 8 |
// actually is the same as .size() -- which is rather confusing! |
| 9 |
// |
| 10 |
// It is strongly recommended that .cap() be avoided; instead, |
| 11 |
// explicitly use .size() or .capacity() as appropriate.) |
| 12 |
|
| 13 |
// instantiate a float array |
| 14 |
float argh[0]; |
| 15 |
|
| 16 |
// print |
| 17 |
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>; |
| 18 |
|
| 19 |
// resize |
| 20 |
4 => argh.size; |
| 21 |
|
| 22 |
// print |
| 23 |
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>; |
| 24 |
|
| 25 |
// set elements |
| 26 |
3.0 => argh[0]; |
| 27 |
4 => argh[1]; |
| 28 |
5.0 => argh[2]; |
| 29 |
6 => argh[3]; |
| 30 |
|
| 31 |
// print |
| 32 |
<<< "contents:", "">>>; |
| 33 |
for( int i; i < argh.size(); i++ ) |
| 34 |
<<< "argh[", i, "]:", argh[i] >>>; |
| 35 |
|
| 36 |
// recap |
| 37 |
2 => argh.size; |
| 38 |
|
| 39 |
// print |
| 40 |
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>; |
| 41 |
|
| 42 |
// clear the contents |
| 43 |
argh.clear(); |
| 44 |
|
| 45 |
// print |
| 46 |
<<< "array size:", argh.size(), "capacity:", argh.capacity() >>>; |