Introduce range based singleton searches for loop queries.
Several loop queries look for a singleton by finding all instances and then
returning whether there is 1 instance or not. This can be improved by
stopping the search after 2 have been found. Introduce generic range
based singleton searches that stop after finding a second value
and use them for these loop queries.
There is no intended functional change other than improved compile-time
efficiency.
I think I would have made separate versions of find_singleton instead of adding AllowRepeats so the parameter would not need to be propagated into the Predicate. However, at least in this case AllowRepeats is not a constant and could made it more complicated.