Lambda: Accessing fields of 'var'ed variable

Hi, I am trying to deal with the following situation: class tr { public: int i; int j; }; vector<tr> v(10); vector<uint> idx(5); for_each(idx.begin(), idx.end(), var(v)[_1].i = 1); This does not compile though, because lambda_functor has no member named i. My understanding is that I need the var before the v (also removing the var results in a compilation error). Am I on the right path? Thanks, Firas. ------------- Dr Firas Swidan, PhD Tel: +972.4.486.6278 E-mail: firas.swidan@intel.commailto:firas.swidan@intel.com Intel Israel (74) Ltd. P.O.Box 1659, Haifa 31015, Israel --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

On Mon, Dec 29, 2008 at 03:31, Swidan, Firas
for_each(idx.begin(), idx.end(), var(v)[_1].i = 1);
This does not compile though, because lambda_functor has no member named i.
I think you always have to use bind with members: for_each(idx.begin(), idx.end(), bind(&tr::i, var(v)[_1]) = 1); Hope that works, ~ Scott
participants (2)
-
Scott McMurray
-
Swidan, Firas