On Tue, Jan 13, 2009 at 12:54 PM, Peter Dimov <pdimov@pdimov.com> wrote:
Robert Jones:


If not, are there some 'standard' techniques to produce a similar effect?

You can achieve something similar by using a combination of boost::bind and Lambda, but it's not 'standard' by any means. :-) Do you have a specific example?

Hi Peter

This is a bit trivial, but it broadly illustrates the point

int a[10][10];
int min=1, max=20;

boost::function< int(size_t,size_t) > element = (var)[_1][_2];

boost::function< bool(size_t, size_t) > exceeds_range = bind( element,_1, _2) > max || bind( element,_1,_2) < min;

I'm not sure I've written that quite right, whether I need all those binds, but the
gist of if is that without local variables I seem to have invoke element() twice.
I guess I could write something like

boost::function< bool( int ) > exceed_detail = _1 > max || _1 < min;
boost::function< bool( size_t, size_t ) > exceeds_range = bind( exceeds_detail, bind( element, _1, _2 ) );

but it seems to introduce additional arbitrary artifacts which is not ideal, and
obscures the logic to my mind.

Thanks, Rob.