Boost logo

Boost Users :

From: ÷ÌÁÄÉÍÉÒ ëÒÁÓÏ×ÓËÉ (vkrasovsky_at_[hidden])
Date: 2004-07-30 01:34:18


Hello Vytautas,

Friday, July 30, 2004, 8:04:16 PM, you wrote:

VL> I am often facing the same thing again and again. Say I have a map:
VL> map< int, Foo* > m;

VL> and I would like to invoke method of Foo on all instances

VL> std::for_each(m.begin(), m.end(), boost::bind(&Foo::method, _1 );

VL> The problem is that map contains pair of key and value, not Foo*. Usually I
VL> create some function taking pair and invoking method needed on .second. But
VL> maybe there is another way to do that?

At present time i'm using expressions like this:

typedef map< int, Foo* > M;

M m;

std::for_each(
   m.begin(),
   m.end(),
   boost::bind(
      Foo::method,
      boost::bind(&M::value_type::second, _1)
   )
);

but maybe there is a way to write it more compact.

-- 
Best regards,
 ÷ÌÁÄÉÍÉÒ                            mailto:vkrasovsky_at_[hidden]

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