假设我找到了符合条件的节点,则需要停止搜索。
最佳答案
解决方案是抛出您已知类型的异常-然后在调用方捕获它。从FAQ:
How do I perform an early exit from an algorithm such as BFS?
Create a visitor that throws an exception when you want to cut off the search, then put your call to breadth_first_search inside of an appropriate try/catch block. This strikes many programmers as a misuse of exceptions, however, much thought was put into the decision to have exceptions has the preferred way to exit early. See boost email discussions for more details.
关于boost-graph - 使用自定义访问者时,如何使用Boost Graph Library停止广度优先搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1500709/