loop -> for_each

Discussion in 'C++' started by ibe, Jan 20, 2006.

  1. ibe

    ibe Guest

    Hi,
    i can't get the clue:
    I have had a loop in my code like this:

    ---snip---

    class Foo {
    accept(Visitor& v) {
    v.visit(*this);
    }
    };

    class Visitor {
    visit (Foo& f) {
    ...
    }
    }

    ....in main...

    Visitor v(arugments, ...);
    for (std::deque<Foo*>::iterator iter = list_.begin();
    iter != m_list.end();
    ++iter) {
    (*iter)->accept(v);
    }

    ---snip---

    by means of the boost::bind i could express the loop with

    std::for_each(list_.begin(), list_.end(),
    bind(mem_fun(&Foo::accept), _1, v));

    fine!
    But now things changed to something like

    std::deque<boost::sha
     
    ibe, Jan 20, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ibe

    loop -> for_each

    ibe, Jan 13, 2006, in forum: C++
    Replies:
    1
    Views:
    346
    Thomas Jakob
    Jan 13, 2006
  2. ibe
    Replies:
    5
    Views:
    387
    Luke Meyers
    Jan 20, 2006
  3. Sarath
    Replies:
    13
    Views:
    720
    V.R. Marinov
    Jun 5, 2007
  4. Skirmish
    Replies:
    9
    Views:
    983
    James Kanze
    Jul 24, 2007
  5. Isaac Won
    Replies:
    9
    Views:
    382
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page