Early exit of algorithms in boost graph such as breadth first search should be done by throwing an exception according to the 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.
I am interested in the actual "thoughts that were put into the decision". So far I failed to find the appropriate posts on the mailing list. The closest I found was this one, stating
If the graph is big, exiting the algorithm by throwing an exception might be the most efficient way ;-). Of course, if you do many invocations on small graphs, it may be the least efficient ;-(.
and this one:
If you have enough callbacks, you can surely do all the same things. I'm not sure what loss of control you fear, but from an efficiency point-of-view it might make sense to exit the algorithm by throwing an exception (no, I'm really NOT kidding).
Which, to me, are no real well-founded justifications for the design decision. Also because we do see huge slow downs when a lot of exceptions are thrown, especially while running the code in a debugger. I am also aware of similar posts on stackoverflow (such as this one or this one) asking on how to terminate the searches. But I know how (by throwing an exception). Yet, none of them provide the reasoning behind the decision.
So my question is: Does anyone know the actual thoughts that went into the decision? And does anyone have an actual link to the boost mailing list post that contains these thoughts that are alluded to in the FAQ?