Boost logo

Boost Users :

From: Irfan Adilovic (boost.ia_mask_at_[hidden])
Date: 2006-08-13 22:00:05


Hi all,

Assuming "v" is an STL container, and "value" is a value the container
can hold, I wish to do the following:

ll::accumulate()(v.begin(), v.end(), true, _1 && (_2 != value));

which works: it returns true if all elements in the container are
different from "value", false otherwise (might require a minute of
thinking to come to that conclusion). Now I wish to make a lambda
expression out of the above piece of code, which accepts "value" as the
operator () argument, in order to be evaluated:

bind(ll::accumulate(), v.begin(), v.end(), true, _1 && (_2 !=
value_placeholder));

where _1 and _2 should be protected but value_placeholder shouldn't
(this is why I used "mixed placeholders" in the subject). In other
words, should the bind-expression be evaluated with (value) as its
operator() argument, only "value_placeholder" must be replaced by
"value", the _1 or _2 placeholders must not.

A simple protect:

protect(_1 && (_2 != value_placeholder))

is obviously wrong, as "value_placeholder" cannot be replaced by "value"
in an expression like:

bind(ll::accumulate(), v.begin(), v.end(), true, protect(_1 && (_2 !=
value_placeholder)))(value);

since "value_placeholder" itself, too, is protected.

How to do this?

I hope this was clear enough, I really tried. :-/

Regards,

-- Irfy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net