diff --git a/OptionalPointee.html b/OptionalPointee.html index dc12693..8b96a45 100644 --- a/OptionalPointee.html +++ b/OptionalPointee.html @@ -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.
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.
-Still, the concept itsef can be used to define a deep equality-test that can +Still, the concept itsef can be used to define deep relational tests that can be used in generic code with any type which models OptionalPointee:

-
-template<class OptionalPointee>
+

Equivalence relation:

+
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) ; }
+} ;
 
-

The preceding generic function has the following semantics:
-If both x and y have valid pointees, it compares pointee's values via (*x == *y).
+

The preceding generic function and function object have the following semantics:
+If both x and y have valid pointees, it compares values via (*x == *y) or (*x < +*y).
If only one has a valid pointee, returns false.
If both have invalid pointees, returns true.

-

equal_pointees() is implemented in optional.hpp

+ +

Less-than relation:

+
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) ; }
+} ;
+
+

The preceding generic function and function object have the following semantics:
+If both x and y have valid pointees, it compares values via (*x == *y) or (*x < +*y).
+If only one has a valid pointee, returns false.
+If both have invalid pointees, returns false.

+

All these functions and function +objects are is implemented in compare_pointees.hpp

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.

@@ -127,4 +155,4 @@ based on the original concept developed by Augustus Saunders. - + \ No newline at end of file diff --git a/include/boost/utility/compare_pointees.hpp b/include/boost/utility/compare_pointees.hpp index e580ae2..e02aaf8 100644 --- a/include/boost/utility/compare_pointees.hpp +++ b/include/boost/utility/compare_pointees.hpp @@ -52,7 +52,7 @@ template 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