Boost logo

Boost Users :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-06-06 14:29:31


There are numerous examples and explanation of using visitors in the BGL
book.

On Wed, 5 Jun 2002, ¹Ú±â¼ö wrote:
yg-boo> Can I use visitor with functor ?
yg-boo> In BGL example on visitor,
yg-boo>
yg-boo> int main()
yg-boo> {
yg-boo> :
yg-boo> boost::breadth_first_search
yg-boo> (G, vertex(0, G), visitor(make_bfs_visitor(
yg-boo> std::make_pair(print_edge("tree", on_tree_edge()),
yg-boo> print_edge("cycle", on_non_tree_edge())))));
yg-boo> :
yg-boo> }
yg-boo>
yg-boo> I want to do like this
yg-boo>
yg-boo> boost::breadth_first_search
yg-boo> (G, vertex(0, G), visitor(make_bfs_visitor(
yg-boo> std::make_pair(print_edge("tree", on_tree_edge(), MyFunctor1() ),
yg-boo> print_edge("cycle", on_non_tree_edge(),
yg-boo> MyFunction2() )))));

The print_edge function is creating a functor. You want to replace that
and just use your functor. The functor you create, in addition to having
an operator(), will also need a typedef event_filter to say which event to
do the action on, like on_tree_edge.

Cheers,
Jeremy

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


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