From 6602068638e9ef61a377140f3a98cc75767903a8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 15 Mar 2005 23:44:42 +0000 Subject: [PATCH] Section on operators. [SVN r27680] --- bind.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bind.html b/bind.html index 8d965c2..8509531 100644 --- a/bind.html +++ b/bind.html @@ -27,6 +27,7 @@ to members

Using nested binds for function composition

+

Overloaded operators

Examples

Using bind with standard algorithms

@@ -280,6 +281,29 @@ std::for_each(v.begin(), v.end(), bind(apply<void>(), _1, 5));

The header boost/bind/protect.hpp contains an implementation of protect. To protect a bind function object from evaluation, use protect(bind(f, ...)).

+

Overloaded operators (new in Boost 1.34)

+

For convenience, the function objects produced by bind overload + the logical not operator ! and the relational operators ==, + !=, <, <=, >, + >=.

+

!bind(f, ...) is equivalent to bind( logical_not(), bind(f, + ...) ), where logical_not is a function object that + takes one argument x and returns !x.

+

bind(f, ...) op x, where op is a relational operator, + is equivalent to bind( relation(), bind(f, ...), x ), where relation + is a function object that takes two arguments a and b and + returns a op b.

+

What this means in practice is that you can conveniently negate the result of + bind:

+

std::remove_if( first, last, !bind( &X::visible, _1 ) ); // remove invisible + objects

+

and compare the result of bind against a value:

+

std::find_if( first, last, bind( &X::name, _1 ) == "peter" );

+

against a placeholder:

+

bind( &X::name, _1 ) == _2

+

or against another bind expression:

+

std::sort( first, last, bind( &X::name, _1 ) < bind( &X::name, _2 ) + ); // sort by name

Examples

Using bind with standard algorithms

class image;