To my understanding, your suggestion was to return the return value of fun(item). That's kinda awkward in this case because it may or maynot execute fun so the return value may or may not exist. Or maybe you meant returning optional<ReturnType> so that the exact same thing as I did in the above can be done?
I suppose you could extend it to pass a functor which had a nullary operator() overload as well which gets invoked if the collection is empty, and return the common return type between the two overloads?
View all comments
Show parent comment
2
u/jk-jeon Jul 31 '26
To my understanding, your suggestion was to return the return value of
fun(item). That's kinda awkward in this case because it may or maynot executefunso the return value may or may not exist. Or maybe you meant returningoptional<ReturnType>so that the exact same thing as I did in the above can be done?