By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Lambda library types as indices in for_each

P: n/a
Hi all. I was wondering, is there any way of using the boost lambda types
as an index for a container? For example:

for_each(indexList.begin(), indexList.end(),
(
somelist[_1].someFunction()
));

Right now it doesn't work because:

error: no match for 'operator[]' in 'somelist[boost::lambda::unnamed::_1]'

Anyway of getting that _1 to turn into, say, an int or string or whatever
type the elements in indexList are? I'm guessing casting's not the
answer :).

Thanks!

Brandt Dusthimer

--
Posted via a free Usenet account from http://www.teranews.com

Nov 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 11 Nov 2006 22:37:39 GMT in comp.lang.c++, "Brandt Dusthimer"
<br****@noemail.netwrote,
>for_each(indexList.begin(), indexList.end(),
(
somelist[_1].someFunction()
));

Right now it doesn't work because:

error: no match for 'operator[]' in 'somelist[boost::lambda::unnamed::_1]'
Quoted from the boost lambda documentation:

Assignment and subscript operators

These operators must be implemented as class members. Consequently, the
left operand must be a lambda expression. For example:

int i;
_1 = i; // ok
i = _1; // not ok. i is not a lambda expression

There is a simple solution around this limitation, described in the
section called “Delaying constants and variables”. In short, the left
hand argument can be explicitly turned into a lambda functor by wrapping
it with a special var function:

var(i) = _1; // ok

Nov 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.