mirror of
https://github.com/boostorg/convert.git
synced 2026-02-18 01:52:22 +00:00
35 lines
1.8 KiB
Plaintext
35 lines
1.8 KiB
Plaintext
[/
|
|
Copyright (c) Vladimir Batov 2009-2014
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
See copy at http://www.boost.org/LICENSE_1_0.txt.
|
|
]
|
|
|
|
[section Return Value]
|
|
|
|
As it was indicated in the previous section `boost::optional` is the actual type returned by
|
|
|
|
boost::optional<TypeOut> boost::convert(TypeIn const&, Converter const&);
|
|
|
|
The signature is ['functionally-complete] and is the most efficient in deploying the underlying converter. That said, the following alternative interface might be potentially better suitable for certain deployment scenarios (or due to personal preferences):
|
|
|
|
Out convert(In const&, Converter const&, Out const& fallback_value);
|
|
Out convert(In const&, Converter const&, Functor const& fallback_functor);
|
|
Out convert(In const&, Converter const&, boost::throw_on_failure);
|
|
|
|
It still provides full support for various program flows and various degrees of conversion-failure detection and processing and can be deployed in a similar fashion as follows:
|
|
|
|
[getting_serious_example5]
|
|
[getting_serious_example7]
|
|
|
|
[note An expectation might be to see the following signature instead:
|
|
|
|
['TypeOut boost::convert(TypeIn const&, Converter const&);]
|
|
|
|
somewhat similar to what `boost::lexical_cast` does. The signature is deceivingly simple and, in reality, it can only handle one single deployment scenario; as in the case of `boost::lexical_cast` that is the exception-throwing conversion-failure detection. Consequently, in commercial software where process flows vary and reliability and operational continuity are important, that limitation often has to be compensated by a considerable amount of additional code (like try/catch blocks, etc.).
|
|
|
|
On the other hand, the `boost::convert` signatures (although more verbose) provide full support for various program flows, behaviorally unambiguous and readable.]
|
|
|
|
[endsect]
|
|
|
|
|