setDefault

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

Given an associative array to modify, a key, and a lazy evaluated default value, attempt to retrieve a value from an associative array. If a value for the given key is not set, set the provided default value in the associative array and return that.

The value will be returned by reference.

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

Parameters

map V1[K]

The associative array to modify.

key K

The key in the associative array.

def V2

A lazy default value.

Return Value

Type: V1

A reference to the value in the associative array.

Meta