no_optional_interface.qbk 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. [/
  2. Copyright (c) Vladimir Batov 2009-2016
  3. Distributed under the Boost Software License, Version 1.0.
  4. See copy at http://www.boost.org/LICENSE_1_0.txt.
  5. ]
  6. [section Alternative Interface]
  7. [:[*['"It's not a question of happiness, it's a requirement. Consider the alternative” Doug Horton]]]
  8. As it was indicated previously [@boost:/libs/optional/index.html `boost::optional`] is the actual type returned by the `boost::convert()` main interface:
  9. boost::optional<TypeOut> boost::convert(TypeIn const&, Converter const&);
  10. The signature is ['functionally-complete] and routinely elided during compilation. Still, the following alternative (and arguably more traditional) interface might be potentially more suitable for certain deployment scenarios (or due to personal preferences):
  11. TypeOut convert(TypeIn const&, Converter const&, TypeOut const& fallback_value);
  12. TypeOut convert(TypeIn const&, Converter const&, Functor const& fallback_func);
  13. TypeOut convert(TypeIn const&, Converter const&, boost::throw_on_failure);
  14. The interface still provides unambiguous behavior and readability, full support for various program flows and various degrees of conversion-failure detection and processing. It can be deployed in a similar fashion as follows:
  15. [getting_serious_example5]
  16. [getting_serious_example7]
  17. Still, the described interfaces are convenience wrappers around the main interface which provides the described behavior with:
  18. [getting_serious_example8]
  19. [endsect] [/section Return Value]