Boost.JSON Logo

PrevUpHomeNext

value_from

Convert an object of type T to value.

Synopsis

Defined in header <boost/json/value_from.hpp>

template<
    class T>
value
value_from(
    T&& t,
    storage_ptr sp = {});
Description

This function attempts to convert an object of type T to value using

In all cases, the conversion is done by calling an overload of tag_invoke, passing an lvalue jv of type value as an argument to ensure that the result of the conversion uses the correct storage_ptr.

The function used to convert an expression e of type T is determined as follows. Let S be the set of all declarations found by argument-dependent lookup for the function call

tag_invoke( value_from_tag(), jv, e )

Then, an attempt to find an applicable library-provided conversion (if any) is made. Add to S

If a library-provided conversion is added to S, it has the form

template<typename U>
void tag_invoke( value_from_tag, value&, U&& );

Using S, overload resolution is performed to find the single best candidate to convert e to value. If more than one function is found or if no viable function is found, the conversion fails. Otherwise, the selected function F is called with F( value_from_tag(), jv, std::forward< T >( from ) ) and the value of jv after modification by F is returned as the result of the conversion.

Exception Safety

Strong guarantee.

Template Parameters

Type

Description

T

The type of the object to convert.

Return Value

t converted to value.

Parameters

Name

Description

t

The object to convert.

sp

A storage pointer referring to the memory resource to use for the returned value. The default argument for this parameter is {}.

See Also

value_to, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf

Convenience header <boost/json.hpp>


PrevUpHomeNext