var.opIndex

var opIndex(string key) ref @safe

Access a child value by key, turning this instance into a map on first use.

Semantics:

  • If this value is currently Type.NULL, it is converted to a map (Type.OBJECT).
  • If this value is not a map after that (i.e., it was a scalar or array), a VarTypeException is thrown.
  • Returns a reference to the stored child var, inserting a default var.init if missing.

    Returns

    A reference to the value stored at key.
const(var) opIndex(string key) ref const @safe

Const overload of opIndex for read-only map access.

Unlike the mutable overload, this does not convert Type.NULL to a map, and does not insert missing keys. It throws a VarTypeException if the value is not a map, or a VarKeyException if the key is not present.

Returns

A const reference to the value stored at key.
var opIndex(size_t index) ref @safe

Index into the array payload and return a reference to the element.

In coercion mode, out-of-range indices grow the array with var.init fill; otherwise a VarIndexException is thrown for out-of-range access.

Preconditions:

  • The current value must be Type.ARRAY (or NULL, which is converted).
  • index must be in range [0 .. length), otherwise a VarIndexException is thrown (non-coercion mode).
const(var) opIndex(size_t index) ref const @safe

Const overload of opIndex for read-only array access.

Returns

A const reference to the element at index.