Boost logo

Boost Users :

From: Robin (robin_at_[hidden])
Date: 2004-06-03 02:54:27


Hi,

The current bind defines the placeholder _1, _2 etc. I was wondering if
there is another placeholder that will deference the placeholder if the
container is holding pointers instead of copies?

Usually I store shared_ptrs in containers instead of direct copies as
they are polymorphic

  class C; // this is our object we are storing

  typedef boost::shared_ptr<C> CSP;

  std::vector<CSP> C_List;

Now we have a function that operates on C

  void Operate(C &c);

  C_List clist; // the list of shared_ptrs to C

  // this won't compile
  std::for_each (clist.begin (), clist.end (),
                 boost::bind (Operator,_1));

I have to make an auxillary function to compile

  void Wrap_Operate (CSP &c)
  {
    Operate(*c);
  }

  std::for_each (clist.begin (), clist.end (),
                 boost::bind (Wrap_Operate, _1));

Is there to avoid making the additional function and have a placeholder
that will dereference directly (eg *_1, *_2)? Can I have the cake and
eat it?

Robin


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