3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Inplace and infix operators
</title>
5 <link rel=
"stylesheet" href=
"../../../../../../doc/src/boostbook.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.74.0">
7 <link rel=
"home" href=
"../../index.html" title=
"Chapter 1. Boost.Icl">
8 <link rel=
"up" href=
"../implementation.html" title=
"Implementation">
9 <link rel=
"prev" href=
"complexity.html" title=
"Complexity">
10 <link rel=
"next" href=
"../function_reference.html" title=
"Function Reference">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../../libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"complexity.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../implementation.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"../function_reference.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>
25 <div class=
"section boost_icl_implementation_inplace_and_infix_operators" lang=
"en">
26 <div class=
"titlepage"><div><div><h3 class=
"title">
27 <a name=
"boost_icl.implementation.inplace_and_infix_operators"></a><a class=
"link" href=
"inplace_and_infix_operators.html" title=
"Inplace and infix operators">Inplace
28 and infix operators
</a>
29 </h3></div></div></div>
31 For the major operations
<span class=
"emphasis"><em>addition, subtraction, intersection
</em></span>
32 of
<span class=
"bold"><strong>icl
</strong></span> containers and for
<span class=
"emphasis"><em>symmetric
33 difference
</em></span> inplace
<code class=
"computeroutput"><span class=
"keyword">operator
</span></code>s
34 <code class=
"computeroutput"><span class=
"special">+=
</span> <span class=
"special">|=,
</span>
35 <span class=
"special">-=,
</span> <span class=
"special">&=
</span></code>
36 and
<code class=
"computeroutput"><span class=
"special">^=
</span></code> are provided.
39 For every
<span class=
"emphasis"><em><span class=
"bold"><strong>inplace
</strong></span></em></span> operator
42 <pre class=
"programlisting"><span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"keyword">operator
</span> <span class=
"identifier">o
</span><span class=
"special">=
</span> <span class=
"special">(
</span><span class=
"identifier">T
</span><span class=
"special">&</span> <span class=
"identifier">object
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">P
</span><span class=
"special">&</span> <span class=
"identifier">operand
</span><span class=
"special">)
</span>
45 the
<span class=
"bold"><strong>icl
</strong></span> provides corresponding
<span class=
"emphasis"><em><span class=
"bold"><strong>infix
</strong></span></em></span> operators.
47 <pre class=
"programlisting"><span class=
"identifier">T
</span> <span class=
"keyword">operator
</span> <span class=
"identifier">o
</span> <span class=
"special">(
</span><span class=
"identifier">T
</span> <span class=
"identifier">object
</span><span class=
"special">,
</span> <span class=
"keyword">const
</span> <span class=
"identifier">P
</span><span class=
"special">&</span> <span class=
"identifier">operand
</span><span class=
"special">){
</span> <span class=
"keyword">return
</span> <span class=
"identifier">object
</span> <span class=
"identifier">o
</span><span class=
"special">=
</span> <span class=
"identifier">operand
</span><span class=
"special">;
</span> <span class=
"special">}
</span>
48 <span class=
"identifier">T
</span> <span class=
"keyword">operator
</span> <span class=
"identifier">o
</span> <span class=
"special">(
</span><span class=
"keyword">const
</span> <span class=
"identifier">P
</span><span class=
"special">&</span> <span class=
"identifier">operand
</span><span class=
"special">,
</span> <span class=
"identifier">T
</span> <span class=
"identifier">object
</span><span class=
"special">){
</span> <span class=
"keyword">return
</span> <span class=
"identifier">object
</span> <span class=
"identifier">o
</span><span class=
"special">=
</span> <span class=
"identifier">operand
</span><span class=
"special">;
</span> <span class=
"special">}
</span>
53 From this implementation of the infix
<code class=
"computeroutput"><span class=
"keyword">operator
</span>
54 <span class=
"identifier">o
</span></code> the compiler will hopefully use
55 return value optimization
<a href=
"http://en.wikipedia.org/wiki/Return_value_optimization" target=
"_top">(RVO)
</a>
56 creating no temporary object and performing one copy of the first argument
57 <code class=
"computeroutput"><span class=
"identifier">object
</span></code>.
59 <div class=
"caution"><table border=
"0" summary=
"Caution">
61 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Caution]" src=
"../../../../../../doc/src/images/caution.png"></td>
62 <th align=
"left">Caution
</th>
64 <tr><td align=
"left" valign=
"top"><p>
65 Compared to the
<span class=
"emphasis"><em>inplace
</em></span> <code class=
"computeroutput"><span class=
"keyword">operator
</span>
66 <span class=
"identifier">o
</span><span class=
"special">=
</span></code>
67 every use of an
<span class=
"emphasis"><em>infix
</em></span> <code class=
"computeroutput"><span class=
"keyword">operator
</span>
68 <span class=
"identifier">o
</span></code> requires
<span class=
"emphasis"><em><span class=
"bold"><strong>one extra copy
</strong></span></em></span> of the first argument
69 <code class=
"computeroutput"><span class=
"identifier">object
</span></code> that passes a container.
73 Use infix operators only, if
75 <div class=
"itemizedlist"><ul type=
"disc">
77 efficiency is not crucial, e.g. the containers copied are small.
80 a concise and short notation is more important than efficiency in your
84 you need the result of operator
<code class=
"computeroutput"><span class=
"identifier">o
</span><span class=
"special">=
</span></code> as a copy anyway.
87 <a name=
"boost_icl.implementation.inplace_and_infix_operators.time_complexity_of_infix__code__phrase_role__identifier__operators__phrase___phrase_role__identifier__o__phrase___code_"></a><h6>
88 <a name=
"id1133408"></a>
89 <a class=
"link" href=
"inplace_and_infix_operators.html#boost_icl.implementation.inplace_and_infix_operators.time_complexity_of_infix__code__phrase_role__identifier__operators__phrase___phrase_role__identifier__o__phrase___code_">Time
90 Complexity of infix
<code class=
"computeroutput"><span class=
"identifier">operators
</span> <span class=
"identifier">o
</span></code></a>
93 The time complexity of all infix operators of the
<span class=
"bold"><strong>icl
</strong></span>
94 is biased by the extra copy of the
<code class=
"computeroutput"><span class=
"identifier">object
</span></code>
95 argument. So all infix
<code class=
"computeroutput"><span class=
"identifier">operators
</span>
96 <span class=
"identifier">o
</span></code> are at least
<span class=
"emphasis"><em>linear
</em></span>
97 in
<code class=
"computeroutput"><span class=
"identifier">n
</span> <span class=
"special">=
</span>
98 <span class=
"identifier">object
</span><span class=
"special">.
</span><span class=
"identifier">iterative_size
</span><span class=
"special">()
</span></code>.
99 Taking this into account, the complexities of all infix operators can be
100 determined from the corresponding inplace
<code class=
"computeroutput"><span class=
"identifier">operators
</span>
101 <span class=
"identifier">o
</span><span class=
"special">=
</span></code>
105 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
106 <td align=
"left"></td>
107 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2007 -
2010 Joachim Faulhaber
<br>Copyright
© 1999 -
2006 Cortex Software GmbH
<p>
108 Distributed under the Boost Software License, Version
1.0. (See accompanying
109 file LICENSE_1_0.txt or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt" target=
"_top">http://www.boost.org/LICENSE_1_0.txt
</a>)
114 <div class=
"spirit-nav">
115 <a accesskey=
"p" href=
"complexity.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../implementation.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"../function_reference.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>