2
0
mirror of https://github.com/boostorg/json.git synced 2026-01-19 04:12:14 +00:00
Files
json/doc/qbk/conversion/forward.qbk

42 lines
1.4 KiB
Plaintext

[/
Copyright (c) 2022 Dmitry Arkhipov (grisumbras@yandex.ru)
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Official repository: https://github.com/boostorg/json
]
[/-----------------------------------------------------------------------------]
[section Avoiding physical dependency]
Some users, particularly library authors, may wish to provide conversions
between their types and __value__, but at the same time would prefer to avoid
having their library depend on Boost.JSON. This is possible to achieve with the
help of a few forward declarations.
[doc_forward_conversion_1]
Note that __value_from__ is declared using an out-parameter, rather then
returning its result. This overload is specifically designed for this use-case.
After that the definitions of `tag_invoke` overloads should be provided. These
overloads have to be templates, since __value__ is only forward-declared and
hence is an incomplete type.
[doc_forward_conversion_2]
As discussed previously, we prefer to define a non-throwing overload of
`tag_invoke` for __try_value_to__, rather then the throwing overload for
__value_to__, as the latter can fallback to the former without performance
degradation.
Forward declarations of contextual conversions are done very similarly:
[doc_forward_conversion_3]
[doc_forward_conversion_4]
[endsect]