Distinguish precondition violations from bugs in implementation
This is especially important as this library -- as I understand -- is meant to be a reference implementation for the C++ Standard Library proposal.
Currently, the implementaiton of the algorithms throws a logic_error both when user provides a "bad" input, as well as when the bug is discovered in the implementation. See these two lines:
- https://github.com/stdgraph/graph-v2/blob/master/include/graph/algorithm/dijkstra_shortest_paths.hpp#L104
- https://github.com/stdgraph/graph-v2/blob/master/include/graph/algorithm/dijkstra_shortest_paths.hpp#L183
Whether the former should be a precondition or a guaranteed run-time check in the library is the subject of another issue, the implementation should indicate more clearly and prominently that some condition is a bug in the implementation.
One common approach is to use macro assert(). Another would be to provide a custom macro, say STD_GRAPH_ASSERT(message), which again, thows a logic_error, but because it is a macro, it clearly indicates that this time we are throwing due to an internal bug.
That all makes sense. I like the use of a macro. Thanks!
Sent from Outlookhttp://aka.ms/weboutlook
From: Andrzej Krzemieński @.> Sent: Saturday, May 10, 2025 7:25 AM To: stdgraph/graph-v2 @.> Cc: Subscribed @.***> Subject: [stdgraph/graph-v2] Distinguish precindition violations from bugs in implementation (Issue #145)
[https://avatars.githubusercontent.com/u/2912717?s=20&v=4]akrzemi1 created an issue (stdgraph/graph-v2#145)https://github.com/stdgraph/graph-v2/issues/145
This is especially important as this library -- as I understand -- is meant to be a reference implementation for the C++ Standard Library proposal.
Currently, the implementaiton of the algorithms throws a logic_error both when user provides a "bad" input, as well as when the bug is discovered in the implementation. See these two lines:
- https://github.com/stdgraph/graph-v2/blob/master/include/graph/algorithm/dijkstra_shortest_paths.hpp#L104
- https://github.com/stdgraph/graph-v2/blob/master/include/graph/algorithm/dijkstra_shortest_paths.hpp#L183
Whether the former should be a precondition or a guaranteed run-time check in the library is the subject of another issuehttps://github.com/stdgraph/P1709/issues/113, the implementation should indicate more clearly and prominently that some condition is a bug in the implementation.
One common approach is to use macro assert(). Another would be to provide a custom macro, say STD_GRAPH_ASSERT(message), which again, thows a logic_error, but because it is a macro, it clearly indicates that this time we are throwing due to an internal bug.
— Reply to this email directly, view it on GitHubhttps://github.com/stdgraph/graph-v2/issues/145, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB7NKEUZJBLEM2OT3PL4CTD25XO4JAVCNFSM6AAAAAB42X3QDWVHI2DSMVQWIX3LMV43ASLTON2WKOZTGA2TIMBUGY3DKNI. You are receiving this because you are subscribed to this thread.Message ID: @.***>