Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

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);
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:

Any other value for I is ill-formed.

Template Parameters

Type

Description

I

The element index to access.

Constraints

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

Return Value

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

Parameters

Name

Description

kvp

The key_value_pair object to access.

Convenience header <boost/json.hpp>


PrevUpHomeNext