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 of get 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 constifI == 0, or -
value&,value const&, orvalue&&ifI == 1.
Using any other value for I is ill-formed.
Constraints
std::is_same_v< std::remove_cvref_t<T>, key_value_pair >
Template Parameters
| Type | Description |
|---|---|
|
The element index to access. |
Return Value
kvp.key() if I == 0, or kvp.value() if I == 1.
Parameters
| Name | Description |
|---|---|
|
The |
Convenience header <boost/json.hpp>