Have search
throw an exception instead of returning zero/range
#20691
Labels
won't change
Indicates that work won't continue on an issue or pull request
Hi, I have some thoughts on the edge case return values for the current
search
API.Currently,
search
describes a failure to match as follows:This means that users of this API must handle the case of unmatching with some non-intuitive check. For example:
It turns out that
first(result) == 0
is the condition that handles the three cases for when the object to search for (the needle) is either a string, a character, or a vector of characters since the API has two different return types depending on the the needle type.The proposal here is to instead throw some type of exception e.g.
UnmatchedException
.The text was updated successfully, but these errors were encountered: