An interesting peculiarity of functions like <ahref="sequences/intrinsics/functions/at.html"title="at"><ttclass="computeroutput"><spanclass="identifier">at</span></tt></a> when applied to a <ahref="sequences/concepts/forward_sequence.html"title="Forward
Sequence">Forward
Sequence</a> like <ahref="sequences/containers/list.html"title="list"><ttclass="computeroutput"><spanclass="identifier">list</span></tt></a> is that what could have been
linear runtime complexity effectively becomes constant O(1) due to compiler
optimization of C++ inlined functions, however deeply recursive (up to a certain
compiler limit of course). Compile time complexity remains linear.
constant compile time complexities. There is an overloaded function, <ttclass="computeroutput"><spanclass="identifier">f</span><spanclass="special">(</span><spanclass="identifier">k</span><spanclass="special">)</span></tt>, for each key <spanclass="emphasis"><em>type</em></span><ttclass="computeroutput"><spanclass="identifier">k</span></tt>. The compiler chooses the appropriate function
Tag dispatching is a generic programming technique for selecting template specializations.
There are typically 3 components involved in the tag dispatching mechanism:
</p>
<divclass="orderedlist"><oltype="1">
<li>
A type for which an appropriate template specialization is required
</li>
<li>
A metafunction that associates the type with a tag type
</li>
<li>
A template that is specialized for the tag type
</li>
</ol></div>
<p>
For example, the fusion <ttclass="computeroutput"><spanclass="identifier">result_of</span><spanclass="special">::</span><spanclass="identifier">begin</span></tt> metafunction
<ttclass="computeroutput"><spanclass="identifier">Sequence</span></tt> is the type for
which a suitable implementation of <ttclass="computeroutput"><spanclass="identifier">result_of</span><spanclass="special">::</span><spanclass="identifier">begin_impl</span></tt>
is required
</li>
<li>
<ttclass="computeroutput"><spanclass="identifier">traits</span><spanclass="special">::</span><spanclass="identifier">tag_of</span></tt> is the metafunction that associates
<ttclass="computeroutput"><spanclass="identifier">Sequence</span></tt> with an appropriate
tag
</li>
<li>
<ttclass="computeroutput"><spanclass="identifier">result_of</span><spanclass="special">::</span><spanclass="identifier">begin_impl</span></tt> is the template which is specialized
containers extend themselves in place though member functions such as <ahref="algorithms/transformation/functions/push_back.html"title="push_back"><ttclass="computeroutput"><spanclass="identifier">push_back</span></tt></a> and <ahref="algorithms/transformation/functions/insert.html"title="insert"><ttclass="computeroutput"><spanclass="identifier">insert</span></tt></a>. <ahref="http://www.boost.org/libs/mpl/index.html"target="_top">MPL</a>
sequences, on the other hand, are extended through "intrinsic" functions
that actually return whole sequences. <ahref="http://www.boost.org/libs/mpl/index.html"target="_top">MPL</a>
is purely functional and can not have side effects. For example, <ahref="http://www.boost.org/libs/mpl/index.html"target="_top">MPL</a>'s
<ttclass="computeroutput"><spanclass="identifier">push_back</span></tt> does not actually
mutate an <ttclass="computeroutput"><spanclass="identifier">mpl</span><spanclass="special">::</span><spanclass="identifier">vector</span></tt>. It can't do that. Instead, it returns
an extended <ttclass="computeroutput"><spanclass="identifier">mpl</span><spanclass="special">::</span><spanclass="identifier">vector</span></tt>.
</p>
<p>
Like <ahref="http://www.boost.org/libs/mpl/index.html"target="_top">MPL</a>, Fusion
too is purely functional and can not have side effects. With runtime efficiency
in mind, Fusion sequences are extended through generic functions that return
are sequences that do not actually contain data, but instead impart an alternative
presentation over the data from one or more underlying sequences. <ahref="sequences/views.html"title="Views">Views</a>
are proxies. They provide an efficient yet purely functional way to work on
potentially expensive sequence operations. For example, given a <ahref="sequences/containers/vector.html"title="vector"><ttclass="computeroutput"><spanclass="identifier">vector</span></tt></a>, Fusion's <ahref="algorithms/transformation/functions/push_back.html"title="push_back"><ttclass="computeroutput"><spanclass="identifier">push_back</span></tt></a> returns a <ahref="sequences/views/joint_view.html"title="joint_view"><ttclass="computeroutput"><spanclass="identifier">joint_view</span></tt></a>, instead of an actual extended
Functions that take in elemental values to form sequences (e.g. <ahref="sequences/generation/functions/make_list.html"title="make_list"><ttclass="computeroutput"><spanclass="identifier">make_list</span></tt></a>) convert their arguments
to something suitable to be stored as a sequence element. In general, the element
returns a <ahref="sequences/containers/list.html"title="list"><ttclass="computeroutput"><spanclass="identifier">list</span></tt></a><ttclass="computeroutput"><spanclass="special"><</span><spanclass="keyword">int</span><spanclass="special">,</span>
Fusion's generation functions (e.g. <ahref="sequences/generation/functions/make_list.html"title="make_list"><ttclass="computeroutput"><spanclass="identifier">make_list</span></tt></a>) by default stores the element
Sometimes the plain non-reference type is not desired. You can use <ttclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">ref</span></tt>
and <ttclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">cref</span></tt> to store references or const references
(respectively) instead. The mechanism does not compromise const correctness
since a const object wrapped with ref results in a tuple element with const
reference type (see the fifth code line below). Examples:
not <ttclass="computeroutput"><spanclass="keyword">const</span><spanclass="keyword">char</span><spanclass="special">*</span></tt>. To get <ahref="sequences/generation/functions/make_list.html"title="make_list"><ttclass="computeroutput"><spanclass="identifier">make_list</span></tt></a> to create a <ahref="sequences/containers/list.html"title="list"><ttclass="computeroutput"><spanclass="identifier">list</span></tt></a> with an element of a non-const
array type one must use the <ttclass="computeroutput"><spanclass="identifier">ref</span></tt>
wrapper (see <ahref="notes.html#fusion.notes.boost__ref"><ttclass="computeroutput"><spanclass="identifier">boost</span><spanclass="special">::</span><spanclass="identifier">ref</span></tt></a>).