Node.opIndex

Get the element at specified index.

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

More...
struct Node
ref
inout(Node)
opIndex
inout @safe
(
T
)
()

Return Value

Type: inout(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 Node narray = Node([11, 12, 13, 14]);
2 Node nmap   = Node(["11", "12", "13", "14"], [11, 12, 13, 14]);
3 
4 assert(narray[0].as!int == 11);
5 assert(null !is collectException(narray[42]));
6 assert(nmap["11"].as!int == 11);
7 assert(nmap["14"].as!int == 14);

Meta