Bind: more convenience operators?

Bind has operator! overloaded to allow convenient notting of bound functions. Is there a specific reason not to overload all other operators in a similar way, for example for defining an AND of two predicates f and g as boost::bind( f, _1 ) && boost::bind( g, _1 )? Arno

Arno Schoedl wrote:
Bind has operator! overloaded to allow convenient notting of bound functions. Is there a specific reason not to overload all other operators in a similar way, for example for defining an AND of two predicates f and g as boost::bind( f, _1 ) && boost::bind( g, _1 )?
Yes, there are specific reasons to not overload all operators, not all of them showstoppers. The reason to not overload operator+ and similar is that boost::bind does no return type deduction; it always produces a function object with a fixed result_type. The reason to not overload operator||, operator&& and operator, (whose return types are known) is that x && y, x || y and x,y are not expressible as bind( fn, x, y ) because of the specific requirements of these operators for evaluation order and shortcut evaluation. They are still doable, of course. If you have a prototype implementation in mind, please do not hesitate to show it. :-)
participants (2)
-
Arno Schoedl
-
Peter Dimov