default_converter.qbk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 Default Converter]
  7. [import ../example/default_converter.cpp]
  8. The explicit converter as in
  9. int i = boost::convert<int>("123", converter).value();
  10. provides considerable flexibility, configurability and efficiency. However, in certain contexts that might be not that important or even counter-productive if, for example, an application relies on certain consistent behavior associated with one particular converter type and configuration. To accommodate such a scenario ['Boost.Convert] introduces the concept of the ['default converter] implemented as `boost::cnv::by_default`.
  11. [important There is no default converter set by default.]
  12. Consequently, without additional configuration steps the following call will fail to compile:
  13. int i = boost::convert<int>("123").value(); // No converter provided
  14. However, after `boost::cnv::by_default` is defined simply as:
  15. [default_converter_declaration_simple]
  16. or potentially configured with additional formatting:
  17. [default_converter_declaration_formatted]
  18. the code compiles and deploys `boost::cnv::cstream` when `boost::convert()` is called without an explicitly supplied converter:
  19. [default_converter_example1]
  20. The trade-off for the convenience is the rigid converter configuration (which in certain contexts might be the desired behavior) and a potential performance impact. When a converter is not provided explicitly, the default converter is created, potentially configured, deployed and destroyed for every `boost::convert()` call. Consequently, if efficiency of this particular component is important, then the implementation of `boost::cnv::by_default` will need to take that into account and to make sure those operations are cheap.
  21. [endsect]