| Home | Libraries | People | FAQ | More

##### try_value_to (2 of 2 overloads)

Convert a `value` to a `result` of `T`.

###### Synopsis

Defined in header `<boost/json/value_to.hpp>`

    template<
        class T>
    result_for< T, value >::type
    try_value_to(
        const value& jv);

###### Description

This function attempts to convert a `value` to `result<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 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:

    result<T> tag_invoke( try_value_to_tag<T>, const value& );

If an error occurs during conversion, the result will store the error code associated with the error. If an exception is thrown, the function will attempt to retrieve the associated error code and return it, otherwise it will return `error::exception`, unless the exception type is `std::bad_alloc`, which will be allowed to propagate.

###### Constraints

    ! std::is_reference< T >::value

###### Exception Safety

Strong guarantee.

###### Template Parameters

Type | Description
--- | ---
`T` | The type to convert to.

###### Parameters

Name | Description
--- | ---
`jv` | The `value` to convert.

###### Return Value

`jv` converted to `result<T>`.

###### See Also

`value_to_tag`, `value_to`, `value_from`, tag_invoke: A general pattern for supporting customisable functions

Convenience header `<boost/json.hpp>`