setDefault

Get or create a value from/in an associative array.

Given an associative array to modify and a key, attempt to retrieve a value from the associative array. If a value for the given key is not set, set the value in the associative array to the default value for the value's type.

The value will be returned by reference.

  1. V1 setDefault(V1[K] map, K key, V2 def)
  2. V setDefault(V[K] map, K key)
    @safe pure nothrow ref
    V
    setDefault
    (
    K
    V
    )
    (
    ref V[K] map
    ,
    K key
    )

Parameters

map V[K]

The associative array to modify.

key K

The key in the associative array.

Return Value

Type: V

A reference to the value in the associative array.

Meta