Functions

Construction

Dynamic variables can be created in various ways.

Expression

Semantics

Conditions

V v

Creates a nullable variable.

Effects:

Default-initializes variable to the nullable type.

Example:

` dynamic::variable data; assert(data.is<dynamic::nullable>()); `

V v(t) V v = t

Creates a variable of given supported type.

Requires:

T shall be a supported type.

Effects:

Direct-initializes variable to value.

Example:

` dynamic::variable data(1); assert(data.is<int>()); `

V v(u) V v = u

Creates a copy of another dynamic variable.

Effects:

Copy-initializes variable with the type and value from another dynamic variable.

Example:

` dynamic::variable other(3.0); dynamic::variable data(other); assert(data.is<double>()); `

V v { u1, u2, u3, …​ } V v = { u1, u2, u3, …​ }

Creates an array from initializer list.

Effects:

List-initializes variable as array from initializer list.

If the initializer list consists of a sequence of pairs, then the values will be stored as an associative array. Otherwise the values will be stored as an array. Nested lists are allowed.

Example:

` dynamic::variable data { null, true, 2, 3.0, "alpha" }; assert(data.is<dynamic::array>()); dynamic::variable data { 1, 2, { 3, 4 }, 5 }; assert(data.is<dynamic::array>()); `

V v { {u1, u2}, {u3, u4}, …​ } V v = { {u1, u2}, {u3, u4}, …​ }

Creates an associative array from initializer list.

Requires: Initializer list shall be a sequence of pairs.[1].

Effects:

List-initializes variable as associative array from initializer list.

If the initializer list consists of a sequence of pairs, then the values will be stored as an associative array. Otherwise the values will be stored as an array. Nested lists are allowed.

Example:

` dynamic::variable data { { "alpha", 1 }, { "bravo", 2 } }; assert(data.is<dynamic::map>()); `

Creates an array from factory method.

Creates an associative array from factory method.

Factory Initialization

Arrays and associated arrays can also be explicitly created with factories.

// Example: List-initializes empty array from factory
auto data = dynamic::array::make();
assert(data.is<dynamic::array>());
assert(data.size() == 0);
// Example: List-initializes array of 42 null values from factory
auto data = dynamic::array::repeat(42, null);
assert(data.is<dynamic::array>());
assert(data.size() == 42);

Capacity

Function

Returns

Description

v.empty()

bool

Returns true if the variable is empty or nullable; return false otherwise.

v.size()

size_type

v.max_size()

size_type

Acessor

The assume_value() functions have a narrow contract. The requested type T must match the stored type exactly. It is undefined behavior if the pre-condition same<T>() is false.

Function

Returns

Description

v.value<T>()

T

Returns stored element by value.

v.operator T()

T

Conversion operator.

Same operation as v.value<T>().

v.assume_value<T>()

T&

Returns stored element by reference.

v.assume_value<T>() const

const T&

v.operator[u]

const variable&

Looks up element by key u.

v.operator[n]

const variable&

Looks up element by integer position n.

Modifiers

Function

Returns

Description

v.clear()

void

Erases all nested elements.]]

v.erase(p)

iterator

Erases element at position p.]]

v.erase(i, j)

iterator

Erases all elements in range [i, `j`).

v.insert(t)

iterator

Inserts element t.

v.insert(p, t)

iterator

Inserts element t at position p.

v.insert(i, j)

void

Inserts elements in range [i, `j`).

v.insert(p, i, j)

void

Inserts elements in range [i, j`) at position `p.

v.swap(u)

Operators

Iterators


1. A pair is a dynamic variable containing an array with exactly two dynamic variables.