value_ref

The type used in initializer lists.

Synopsis

Defined in header <boost/json/value_ref.hpp>.

class value_ref;

Member Functions

Name Description

value_ref [constructor]

Constructor.

Description

This type is used in initializer lists for lazy construction of and assignment to the container types value, array, and object. The two types of initializer lists used are:

  • std::initializer_list< value_ref > for constructing or assigning a value or array, and

  • std::initializer_list< std::pair< string_view, value_ref > > for constructing or assigning an object.

A value_ref uses reference semantics. Creation of the actual container from the initializer list is lazily deferred until the list is used. This means that the boost::container::pmr::memory_resource used to construct a container can be specified after the point where the initializer list is specified.

Example

This example demonstrates how a user-defined type containing a JSON value can be constructed from an initializer list:

class my_type
{
    value jv_;

public:
    my_type( std::initializer_list< value_ref > init )
        : jv_(init)
    {
    }
};

Never declare a variable of type std::initializer_list except in function parameter lists, otherwise the behavior may be undefined.

See Also

Convenience header <boost/json.hpp>.