...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Convert an object of type T
to value
.
Defined in header <boost/json/value_from.hpp>
template< class T, class Context>value
value_from( T&& t, Context const& ctx,storage_ptr
sp = {});
This function attempts to convert an object of type T
to value
using
value
's
constructors,
tag_invoke
.
Out of the box the function supports types satisfying SequenceContainer,
arrays, arithmetic types, bool
,
std::tuple
, std::pair
,
std::variant
, std::optional
,
std::monostate
, and std::nullopt_t
.
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 > void tag_invoke( value_from_tag, value&, T, const Context& , const FullContext& );
or
void tag_invoke( value_from_tag, value&, T, const Context& );
or
void tag_invoke( value_from_tag, value&, T );
The overloads are checked for existence in that order and the first that matches will be selected.
A value
constructed with the storage_ptr
passed to value_from
is passed as the second
argument to ensure that the memory resource is correctly propagated.
Strong guarantee.
Type |
Description |
---|---|
|
The type of the object to convert. |
|
The type of context passed to the conversion function. |
t
converted to value
.
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 |
value_from_tag
,
value_to
,
tag_invoke:
A general pattern for supporting customisable functions
Convenience header <boost/json.hpp>