en	= Value Conversion While the <<ref_value>> container makes it easy to create ad-hoc structures, often it is necessary to convert between JSON and user-defined types or types from the standard library.

en	The function template <<ref_value_from>> provides an interface to construct a <<ref_value>> from a type `T`. The function template <<ref_value_to>> converts in the opposite direction, from a type `T` to <<ref_value>>. Both support a wide variety of different https://en.cppreference.com/w/cpp/language/types[fundamental types], such as `int` or `double`, standard library types, such as `std::string` or `std::vector<T>`, and can be extended to support user-defined types.

en	For the type `T`, the appropriate conversion approach is chosen from the following list of categories. The first matching category is selected.

en	Category of T

en	Comment

en	`value_from` behavior

en	`value_to` behavior

en	Custom conversion.

en	Custom behavior.

en	Boost.JSON container.

en	The result is equal to the input value.

en	`bool`

en	https://en.cppreference.com/w/cpp/types/is_arithmetic[Arithmetic type]

en	a| The result is a number equal to input and has the type

en	`std::int64_t`, if `T` is a signed integer'; or

en	`std::uint64_t`, if `T` is an unsigned integer; or

en	`double` otherwise.

en	The result is created via <<ref_value_to_number>>.

en	Type satisfying <<ref_is_null_like>>

en	Intended for types like {std_monostate}.

en	The result is a null value.

en	The result is default-constructed.

en	Type satisfying <<ref_is_string_like>>.

en	A sequence of `char`s, e.g. `std::string`.

en	The result is a <<ref_string>>.

en	The result is constructed from a <<ref_string_view>>.

en	Type satisfying <<ref_is_variant_like>>.

en	`std::variant` and similar types, e.g. `boost::variant2::variant`.

en	The result is equal to the result of conversion of the active variant

en	alternative. |The result holds the first alternative for which a conversion succeeds.

en	Type satisfying <<ref_is_optional_like>>

en	If the input value is empty, the result is a `null`. Otherwise it is

en	equivalent to conversion of the object stored inside of optional. |The result is default constructed if the input value is `null`. Otherwise the result is constructed from the result of conversion of the input to the type stored in optional.

en	Type satisfying <<ref_is_map_like>>.

en	A one-to-one mapping (e.g. `std::map`) with string-like keys.

en	The result is an <<ref_object>>.

en	The result is default-constructed, and elements are `insert`-ed at the end.

en	Type satisfying <<ref_is_sequence_like>>.

en	A sequence of elements, e.g. `std::vector`.

en	The result is an <<ref_array>>.

en	Type satisfying <<ref_is_tuple_like>>.

en	A heterogenous sequence with fixed size, e.g. `std::tuple` and `std::pair`.

en	The result is constructed with the array elements as constructor arguments.

en	Type satisfying <<ref_is_described_class>>

en	The result is an <<ref_object>> with described members' names as keys.

en	The result is default-constructed and described members are assigned

en	corresponding values.

en	Type satisfying <<ref_is_described_enum>>

en	If the input value is equal to one of the described enumerators, the result is

en	a <<ref_string>>, containing its name. Otherwise it's equal to the input value converted to its underlying type. |The result is the described enumerator, corresponding to the input <<ref_string>>.

en	Type satisfying <<ref_is_path_like>>.

en	`std::filesystem::path` and similar types, e.g. `boost::filesystem::path`.

en	The result is equal to the result of `path::generic_string`.

en	The result is constructed from two pointers to `const char`.

en	For composite types (sequences, tuples, described classes, etc.) conversion of contained objects is applied recursively. For example:

en	Here, the map is converted into an <<ref_object>>, since it matches <<ref_is_map_like>>. Each of its keys is converted into a <<ref_string>>, as `std::string` matches <<ref_is_string_like>>, and each of its values is converted into an <<ref_array>>, as `std::pair` matches <<ref_is_tuple_like>>. Finally, elements of pairs are converted into a `std::int64_t` number and a `bool`.

en	:leveloffset: +1

en	include::custom.adoc[] include::nothrow.adoc[] include::alloc.adoc[] include::context.adoc[] include::forward.adoc[] include::direct.adoc[] include::guidelines.adoc[]

en	:leveloffset: -1