value_to
Convert a value to an object of type T.
Synopsis
Defined in header <boost/json/value_to.hpp>.
Description
This function attempts to convert a value to T using
-
one of
value's accessors, or -
a library-provided generic conversion, or
-
a user-provided overload of
tag_invoke.
Out of the box the function supports default constructible types satisfying SequenceContainer, arrays, arithmetic types, bool, std::tuple, std::pair, std::optional, std::variant, std::nullptr_t, and structs and enums described using Boost.Describe.
Conversion of other types is done by calling an overload of tag_invoke found by argument-dependent lookup. Its signature should be similar to:
template< class FullContext >
T tag_invoke( value_to_tag<T>, const value&, const Context& , const FullContext& );
or
T tag_invoke( value_to_tag<T>, const value&, const Context& );
or
result<T> tag_invoke( value_to_tag<T>, const value& );
The overloads are checked for existence in that order and the first that matches will be selected.
The object returned by the function call is returned by value_to as the result of the conversion.
The ctx argument can be used either as a tag type to provide conversions for third-party types, or to pass extra data to the conversion function.
Overload (3) is deleted and participates in overload resolution only when U is not value. The overload exists to prevent unintented creation of temporary value instances, e.g.
auto flag = value_to<bool>(true);
Constraints
! std::is_reference< T >::value
Exception Safety
Strong guarantee.
Template Parameters
| Type | Description |
|---|---|
|
The type to convert to. |
|
The type of context passed to the conversion function. |
Return Value
jv converted to result<T>.
Parameters
| Name | Description |
|---|---|
|
The |
|
Context passed to the conversion function. |
See Also
Convenience header <boost/json.hpp>