get

Tuple-like element access.

Synopsis

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

template<
    std::size_t I,
    class T>
see below
get(
    T&& kvp) noexcept;

Description

This overload permits the key and value of a key_value_pair to be accessed by index. For example:

key_value_pair kvp("num", 42);

string_view key = get<0>(kvp);
value& jv = get<1>(kvp);

Structured Bindings

When using C++17 or greater, objects of type key_value_pair may be used to initialize structured bindings:

key_value_pair kvp("num", 42);

auto& [key, value] = kvp;

Depending on the value of I, the return type will be:

  • string_view const if I == 0, or

  • value&, value const&, or value&& if I == 1.

Any other value for I is ill-formed.

Template Parameters

Type Description

I

The element index to access.

Return Value

kvp.key() if I == 0, or kvp.value() if I == 1.

Parameters

Name Description

kvp

The key_value_pair object to access.

Constraints

std::is_same_v< std::remove_cvref_t<T>, key_value_pair >

Convenience header <boost/json.hpp>