What exactly is the reason that in STL at least all ranges-related algorithms are wrapped in structures, like possible implementation in std::ranges::upper_bound:
struct upper_bound_fn
{
template</*…*/>
constexpr I operator()(/*...*) const
{ /* */ }
};
inline constexpr upper_bound_fn upper_bound;
(When I try to implement function template without structure, I am getting type-related errors, but most likely this is not related and I just need to write it more careful.)
I don’t see any internal states to keep in structure (like internal information between the calls), so this is not the case. Although, other algorithms could have, so this could be done for consistency.
Another option is to simplify passing these algorithms as function object to other STL algorithms.
Anyway, I am sure that these are not the only cases and there is much more straightforward reasoning for this choice. Can you please help to find it?