File: array_associative.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 (37 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (2)
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
// declare regular array (capacity doesn't matter so much)
float foo[4];

// use as int-based array
2.5 => foo[0];

// use as associative array with key "yoyo"
4.0 => foo["yoyo"];

// access as associative (print)
<<< foo["yoyo"] >>>;

// access empty element
<<< foo["gaga"] >>>;  // -> should print 0.0

// add a second associative element
44.0 => foo["yiyi"];

// get the array keys with all of the keys in the array
string keys[0];
foo.getKeys(keys);

// print all keys current in foo
for( auto key : keys )
{
    <<< "key:", key >>>;
}

// isInMap
<<< "(isInMap?)",
    "\nyiyi:", foo.isInMap("yiyi"),
    "\nyoyo:", foo.isInMap("yoyo"),
    "\ngaga:", foo.isInMap("gaga"),
    "\nNONO:", foo.isInMap("NONO") >>>;

// call .help() on an array to get more information about its type, methods, etc.
// foo.help();