value_from
Convert an object of type T to value.
Synopsis
Defined in header <boost/json/value_from.hpp>.
template<
class T,
class Context>
void
value_from(
T&& t,
Context const& ctx,
value& jv); (1)
template<
class T,
class Context>
value
value_from(
T&& t,
Context const& ctx,
storage_ptr sp = {}); (2)
template<
class T>
void
value_from(
T&& t,
value& jv); (3)
template<
class T>
value
value_from(
T&& t,
storage_ptr sp = {}); (4)
Description
This function attempts to convert an object of type T to value using
-
one of
value's constructors, -
a library-provided generic conversion, or
-
a user-provided overload of
tag_invoke.
In order to perform the conversion the function selects an appropriate implementation based on the types T and Context (if provided).
-
If
Contextis available and is notstd::tuple<C...>-
check if
use_category<T, Context>::valueis notconversion_category::unknown; otherwise -
check if a
tag_invokeoverload from the list below that takes aContext const&exists.
-
-
Otherwise, if
Contextis available, and isstd::tuple<C...>repeat steps 1 and 2 recursively for everyCuntil either step 1.a or 1.b succeeds for someC. -
Failing that,
-
check if
use_category<T>::valueis notconversion_category::unknown; otherwise -
check if a
tag_invokeoverload from the list below that takes only 2 parameters exists; otherwise -
check if
Tis one ofvalue,array,object, orstring; otherwise -
check if
Tmatches one of the categories of types described in the table "Conversion categories" in Value Conversion section.
-
These steps determine both the appropriate category of conversion for T, and, if necessary, the effective context C that will be used for conversion. If the category is selected on steps 1.a, 3.a, 3.c, or 3.d, the library provides a suitable conversion implementation. If the category is selected on steps 2.b or 3.b, then a user-provided tag_invoke overload is used.
The overloads of tag_invoke that will be considered by this function are in the following list. Overloads that appear higher in the list have higher priority.
template< class FullContext >
void tag_invoke( value_from_tag, value&, T, const Context&, const FullContext& );
void tag_invoke( value_from_tag, value&, T, const Context& );
void tag_invoke( value_from_tag, value&, T );
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.
Overloads (2) and (4) construct their return value using the storage_ptr sp, which ensures that the memory resource is correctly propagated.
Exception Safety
Strong guarantee.
Template Parameters
| Type | Description |
|---|---|
|
The type of the object to convert. |
|
The type of context passed to the conversion function. |
Return Value
Overloads (2) and (4) return t converted to value. Overloads (1) and 3 return void instead and pass their result via the out parameter jv.
Parameters
| Name | Description |
|---|---|
|
The object to convert. |
|
Context passed to the conversion function. |
|
|
|
A storage pointer referring to the memory resource to use for the returned |
See Also
Convenience header <boost/json.hpp>