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 <spanclass="emphasis"><em>Boost.Convert</em></span> introduces the concept of the
<spanclass="emphasis"><em>default converter</em></span> implemented as <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">cnv</span><spanclass="special">::</span><spanclass="identifier">by_default</span></code>.
Consequently, without additional configuration steps the following call will
fail to compile:
</p>
<preclass="programlisting"><spanclass="keyword">int</span><spanclass="identifier">i</span><spanclass="special">=</span><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">convert</span><spanclass="special"><</span><spanclass="keyword">int</span><spanclass="special">>(</span><spanclass="string">"123"</span><spanclass="special">).</span><spanclass="identifier">value</span><spanclass="special">();</span><spanclass="comment">// No converter provided</span>
</pre>
<p>
However, after <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">cnv</span><spanclass="special">::</span><spanclass="identifier">by_default</span></code>
the code compiles and deploys <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">cnv</span><spanclass="special">::</span><spanclass="identifier">cstream</span></code> when <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">convert</span><spanclass="special">()</span></code> is called without an explicitly supplied
converter:
</p>
<p>
</p>
<preclass="programlisting"><spanclass="comment">// No explicit converter provided. boost::cnv::by_default is used.</span>
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 <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">convert</span><spanclass="special">()</span></code> call. Consequently, if efficiency of this
particular component is important, then the implementation of <codeclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">cnv</span><spanclass="special">::</span><spanclass="identifier">by_default</span></code>
will need to take that into account and to make sure those operations are cheap.
Distributed under the Boost Software License, Version 1.0. See copy at <ahref="http://www.boost.org/LICENSE_1_0.txt"target="_top">http://www.boost.org/LICENSE_1_0.txt</a>.