Merged 52463

[SVN r55485]
This commit is contained in:
Daniel Frey 2009-08-09 13:45:03 +00:00
parent 61755605af
commit d5291d08b8

View File

@ -132,18 +132,18 @@
class MyInt class MyInt
: boost::operators<MyInt> : boost::operators<MyInt>
{ {
bool operator<(const MyInt& x) const; bool operator<(const MyInt& x) const;
bool operator==(const MyInt& x) const; bool operator==(const MyInt& x) const;
MyInt& operator+=(const MyInt& x); MyInt& operator+=(const MyInt& x);
MyInt& operator-=(const MyInt& x); MyInt& operator-=(const MyInt& x);
MyInt& operator*=(const MyInt& x); MyInt& operator*=(const MyInt& x);
MyInt& operator/=(const MyInt& x); MyInt& operator/=(const MyInt& x);
MyInt& operator%=(const MyInt& x); MyInt& operator%=(const MyInt& x);
MyInt& operator|=(const MyInt& x); MyInt& operator|=(const MyInt& x);
MyInt& operator&=(const MyInt& x); MyInt& operator&=(const MyInt& x);
MyInt& operator^=(const MyInt& x); MyInt& operator^=(const MyInt& x);
MyInt& operator++(); MyInt& operator++();
MyInt& operator--(); MyInt& operator--();
}; };
</pre> </pre>
</blockquote> </blockquote>
@ -345,7 +345,7 @@ class MyInt
</ul> </ul>
<p>As Daniel Kr&uuml;gler pointed out, this technique violates 14.6.5/2 <p>As Daniel Kr&uuml;gler pointed out, this technique violates 14.6.5/2
and is thus non-portable. The reasoning is, that the operators injected and is thus non-portable. The reasoning is, that the operators injected
by the instantiation of e.g. by the instantiation of e.g.
<code>less_than_comparable&lt;myclass&gt;</code> can not be found <code>less_than_comparable&lt;myclass&gt;</code> can not be found
by ADL according to the rules given by 3.4.2/2, since myclass is by ADL according to the rules given by 3.4.2/2, since myclass is
@ -445,6 +445,9 @@ const point&lt;float&gt; pi_over_4_normalized = pi_over_4 / length(pi_over_4);
optional template parameter <code>B</code>, which is not shown, for the optional template parameter <code>B</code>, which is not shown, for the
<a href="#chaining">base class chaining</a> technique.</p> <a href="#chaining">base class chaining</a> technique.</p>
<p>The primary operand type <code>T</code> needs to be of class type,
built-in types are not supported.</p>
<table cellpadding="5" border="1" align="center"> <table cellpadding="5" border="1" align="center">
<caption> <caption>
Simple Arithmetic Operator Template Classes Simple Arithmetic Operator Template Classes
@ -917,7 +920,7 @@ T operator+( const T&amp; lhs, const T&amp; rhs )
created, <code>operator+=</code> is called on it and it is copied to the created, <code>operator+=</code> is called on it and it is copied to the
function return value (which is another unnamed object of type function return value (which is another unnamed object of type
<code>T</code>). The standard doesn't generally allow the intermediate <code>T</code>). The standard doesn't generally allow the intermediate
object to be optimized away: object to be optimized away:
<blockquote> <blockquote>
3.7.2/2: Automatic storage duration<br> 3.7.2/2: Automatic storage duration<br>
@ -928,7 +931,7 @@ T operator+( const T&amp; lhs, const T&amp; rhs )
unused, except that a class object or its copy may be eliminated as unused, except that a class object or its copy may be eliminated as
specified in 12.8. specified in 12.8.
</blockquote> </blockquote>
The reference to 12.8 is important for us: The reference to 12.8 is important for us:
<blockquote> <blockquote>
12.8/15: Copying class objects<br> 12.8/15: Copying class objects<br>
@ -942,7 +945,7 @@ T operator+( const T&amp; lhs, const T&amp; rhs )
</blockquote> </blockquote>
This optimization is known as the named return value optimization (NRVO), This optimization is known as the named return value optimization (NRVO),
which leads us to the following implementation for which leads us to the following implementation for
<code>operator+</code>: <code>operator+</code>:
<pre> <pre>
T operator+( const T&amp; lhs, const T&amp; rhs ) T operator+( const T&amp; lhs, const T&amp; rhs )
{ {
@ -956,7 +959,7 @@ T operator+( const T&amp; lhs, const T&amp; rhs )
even implement it in an incorrect way which makes it useless here. even implement it in an incorrect way which makes it useless here.
Without the NRVO, the NRVO-friendly code is no worse than the original Without the NRVO, the NRVO-friendly code is no worse than the original
code showed above, but there is another possible implementation, which code showed above, but there is another possible implementation, which
has some very special properties: has some very special properties:
<pre> <pre>
T operator+( T lhs, const T&amp; rhs ) T operator+( T lhs, const T&amp; rhs )
{ {
@ -982,7 +985,7 @@ T operator+( T lhs, const T&amp; rhs )
will force the NRVO-friendly implementation to be used even for compilers will force the NRVO-friendly implementation to be used even for compilers
that don't implement the NRVO. <br> that don't implement the NRVO. <br>
<br> <br>
<h3><a name="grpd_oprs">Grouped Arithmetic Operators</a></h3> <h3><a name="grpd_oprs">Grouped Arithmetic Operators</a></h3>
<p>The following templates provide common groups of related operations. <p>The following templates provide common groups of related operations.
@ -1864,7 +1867,7 @@ T operator+( T lhs, const T&amp; rhs )
V, D, P, R&gt;</a></code></td> V, D, P, R&gt;</a></code></td>
<td> <td>
Supports the operations and has the requirements of Supports the operations and has the requirements of
<ul> <ul>
<li><code><a href="#input_iteratable">input_iteratable&lt;T, <li><code><a href="#input_iteratable">input_iteratable&lt;T,
@ -1878,7 +1881,7 @@ T operator+( T lhs, const T&amp; rhs )
"output_iterator_helper">output_iterator_helper&lt;T&gt;</a></code></td> "output_iterator_helper">output_iterator_helper&lt;T&gt;</a></code></td>
<td> <td>
Supports the operations and has the requirements of Supports the operations and has the requirements of
<ul> <ul>
<li><code><a href= <li><code><a href=
@ -1894,7 +1897,7 @@ T operator+( T lhs, const T&amp; rhs )
R&gt;</a></code></td> R&gt;</a></code></td>
<td> <td>
Supports the operations and has the requirements of Supports the operations and has the requirements of
<ul> <ul>
<li><code><a href="#forward_iteratable">forward_iteratable&lt;T, <li><code><a href="#forward_iteratable">forward_iteratable&lt;T,
@ -1909,7 +1912,7 @@ T operator+( T lhs, const T&amp; rhs )
V, D, P, R&gt;</a></code></td> V, D, P, R&gt;</a></code></td>
<td> <td>
Supports the operations and has the requirements of Supports the operations and has the requirements of
<ul> <ul>
<li><code><a href= <li><code><a href=
@ -1925,7 +1928,7 @@ T operator+( T lhs, const T&amp; rhs )
V, D, P, R&gt;</a></code></td> V, D, P, R&gt;</a></code></td>
<td> <td>
Supports the operations and has the requirements of Supports the operations and has the requirements of
<ul> <ul>
<li><code><a href= <li><code><a href=
@ -1976,8 +1979,8 @@ struct function_output_iterator
template&lt;typename T&gt; template&lt;typename T&gt;
function_output_iterator&amp; operator=(T const&amp; value) function_output_iterator&amp; operator=(T const&amp; value)
{ {
this-&gt;func(value); this-&gt;func(value);
return *this; return *this;
} }
private: private:
@ -2130,8 +2133,8 @@ public:
<p>Revised: 7 Aug 2008</p> <p>Revised: 7 Aug 2008</p>
<p>Copyright &copy; Beman Dawes, David Abrahams, 1999-2001.</p> <p>Copyright &copy; Beman Dawes, David Abrahams, 1999-2001.</p>
<p>Copyright &copy; Daniel Frey, 2002-2008.</p> <p>Copyright &copy; Daniel Frey, 2002-2009.</p>
<p>Use, modification, and distribution is subject to the Boost Software <p>Use, modification, and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file License, Version 1.0. (See accompanying file
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
<a href="http://www.boost.org/LICENSE_1_0.txt"> <a href="http://www.boost.org/LICENSE_1_0.txt">