Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2005-06-22 11:44:49


On Jun 13, 2005, at 9:23 AM, martin f krafft wrote:

> This may seem like a silly question, but how does one actually
> search with DFS or BFS? Say I want to find the first node for which
> a predicate returns true in a BFS traversal starting at node N...
>
> The function signatures don't have a parameter for "criteria" or
> "predicate", so I guess it's up for a Visitor to implement such
> a check. What is not clear to me is how the visitor functions can
> break out of the search once a condition is true.

The typical way we handle this is to write a visitor that checks the
predicate and, when it returns "true" just throw an exception.
depth_first_visit actually has a "TerminatorFunc" parameter that does
what you want, but it isn't present in the other search algorithms
(although it probably should be).

        Doug


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