Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-02-26 14:34:30

John Torjo wrote:
> Imagine this:
> struct test {
> int i;
> std::string s;
> };
> std::vector<test> tests;
> // ... fill
> void set(int & i, int val) { i = val };
> int val = 10;
> // for each obj from vector, set obj.i = val;
> std::for_each( tests.begin(), tests.end(), bind(&decrement,
> bind(mem_fn(&test::i),_1), val);

Out of curiosity, do you really need this functionality?

The current implementation fails with the above example because of its
"portable" nature (i.e. support for nonconforming compilers), but quality
implementations of the TR1 proposal (Hi Howard!) are actually supposed to
handle this code both as written (typos aside), and with the shorthand
bind(&test::i, _1) applied. (The & before 'decrement' is also redundant.)

You can persuade the current implementation to allow you to modify a member
with bind<int&>(mem_fn(&test::i), _1).

Boost list run by bdawes at, gregod at, cpdaniel at, john at