| Home | Libraries | People | FAQ | More

##### value_from (1 of 2 overloads)

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

- one of `value`'s constructors,
- a library-provided generic conversion, or
- a user-provided overload of `tag_invoke`.

In all cases, the conversion is done by calling an overload of `tag_invoke` found by argument-dependent lookup. Its signature should be similar to:

    void tag_invoke( value_from_tag, value&, T );

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.

###### 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_from_tag`, `value_to`, tag_invoke: A general pattern for supporting customisable functions

Convenience header `<boost/json.hpp>`