Node.opIndex

Get the element at specified index.

If the node is a sequence, index must be integral.

More...
struct Node
ref
opIndex
@trusted
(
T
)
()

Return Value

Type: Node

Value corresponding to the index.

Detailed Description

If the node is a mapping, return the value corresponding to the first key equal to index. containsKey() can be used to determine if a mapping has a specific key.

To get element at a null index, use YAMLNull for index.

Throws

NodeException if the index could not be found, non-integral index is used with a sequence or the node is not a collection.

Examples

1 writeln("D:YAML Node opIndex unittest");
2 alias Node.Value Value;
3 alias Node.Pair Pair;
4 
5 Node narray = Node([11, 12, 13, 14]);
6 Node nmap   = Node(["11", "12", "13", "14"], [11, 12, 13, 14]);
7 
8 assert(narray[0].as!int == 11);
9 assert(null !is collectException(narray[42]));
10 assert(nmap["11"].as!int == 11);
11 assert(nmap["14"].as!int == 14);

Meta