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.
7 [section Default Converter]
9 [import ../example/default_converter.cpp]
11 The explicitly provided converter as in
13 int i = boost::convert<int>("123", converter).value();
15 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`.
17 [important There is no default converter set by default.]
19 Consequently, without additional configuration steps the following call will fail to compile:
21 int i = boost::convert<int>("123").value(); // No converter provided
23 However, after `boost::cnv::by_default` is defined simply as:
25 [default_converter_declaration_simple]
27 or potentially configured with additional formatting:
29 [default_converter_declaration_formatted]
31 the code compiles and deploys `boost::cnv::cstream` when `boost::convert()` is called without an explicitly supplied converter:
33 [default_converter_example1]
35 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.