mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Fixed a bug in the semantics of less_pointees()
[SVN r21132]
This commit is contained in:
parent
61fb5a0b8f
commit
ec36cd8c54
@ -97,22 +97,50 @@ But boost::optional<T>, on the other hand, which is also a model of Option
|
||||
deep-copy and deep-relational semantics.<br>
|
||||
If generic code is written for this concept, it is important not to use relational
|
||||
operators directly because the semantics might be different depending on the actual type.<br>
|
||||
Still, the concept itsef can be used to define a <i>deep</i> equality-test that can
|
||||
Still, the concept itsef can be used to define <i>deep</i> relational tests that can
|
||||
be used in generic code with any type which models OptionalPointee:</p>
|
||||
<a name="equal"></a>
|
||||
<pre>
|
||||
template<class OptionalPointee>
|
||||
<p><u>Equivalence relation:</u></p>
|
||||
<pre>template<class OptionalPointee>
|
||||
inline
|
||||
bool equal_pointees ( OptionalPointee const& x, OptionalPointee const& y )
|
||||
{
|
||||
return (!x) != (!y) ? false : ( !x ? true : (*x) == (*y) ) ;
|
||||
}
|
||||
template<class OptionalPointee>
|
||||
struct equal_pointees_t : std::binary_function<bool,OptionalPointee,OptionalPointee>
|
||||
{
|
||||
bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
|
||||
{ return equal_pointees(x,y) ; }
|
||||
} ;
|
||||
</pre>
|
||||
<p>The preceding generic function has the following semantics:<br>
|
||||
If both x and y have valid pointees, it compares pointee's values via (*x == *y).<br>
|
||||
<p>The preceding generic function and function object have the following semantics:<br>
|
||||
If both x and y have valid pointees, it compares values via (*x == *y) or (*x <
|
||||
*y).<br>
|
||||
If only one has a valid pointee, returns false.<br>
|
||||
If both have invalid pointees, returns true.</p>
|
||||
<p><code>equal_pointees()</code> is implemented in <a href="../../boost/optional.hpp">optional.hpp</a></p>
|
||||
<a name="less"></a>
|
||||
<p><u>Less-than relation:</u></p>
|
||||
<pre>template<class OptionalPointee>
|
||||
inline
|
||||
bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y )
|
||||
{
|
||||
return (!x) != (!y) ? false : ( !x ? false : (*x) == (*y) ) ;
|
||||
}
|
||||
template<class OptionalPointee>
|
||||
struct less_pointees_t : std::binary_function<bool,OptionalPointee,OptionalPointee>
|
||||
{
|
||||
bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
|
||||
{ return less_pointees(x,y) ; }
|
||||
} ;
|
||||
</pre>
|
||||
<p>The preceding generic function and function object have the following semantics:<br>
|
||||
If both x and y have valid pointees, it compares values via (*x == *y) or (*x <
|
||||
*y).<br>
|
||||
If only one has a valid pointee, returns false.<br>
|
||||
If both have invalid pointees, returns false.</p>
|
||||
<p>All these functions and function
|
||||
objects are is implemented in <a href="../../boost/utility/compare_pointees.hpp">compare_pointees.hpp</a></p>
|
||||
<p>Notice that OptionalPointee does not imply aliasing (and optional<> for instance does not alias);
|
||||
so direct usage of relational operators with the implied aliasing of shallow semantics
|
||||
-as with pointers- should not be used with generic code written for this concept.</p>
|
||||
|
@ -52,7 +52,7 @@ template<class OptionalPointee>
|
||||
inline
|
||||
bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y )
|
||||
{
|
||||
return !y ? false : ( !x ? true : (*x) < (*y) ) ;
|
||||
return !y ? false : ( !x ? false : (*x) < (*y) ) ;
|
||||
}
|
||||
|
||||
template<class OptionalPointee>
|
||||
|
Loading…
x
Reference in New Issue
Block a user