I've been trying to re-read the six (!) different threads about the
patch that introduced the <bits/predefined_ops.h> header because I
find the header confusing and have some questions about it.
At the time I thought removing code from <bits/stl_algo.h> was good,
but now 3-4 years later I can't figure out what any of the algos are
doing, because of all the __ops::__iter_comp_val calls to create
mysterious function objects.
The naming of the function objects seems rather arbitrary. We have
_Iter_equal_to_iter and _Iter_equals_iter. One of them is stateless
and binary, one is stateful and unary (and stores the iterator's
reference type, which causes PR78346). Can you guess which is which by
the names? I can't. Shouldn't the names indicate whether they are
unary or binary function objects? Then we have a function __pred_iter
that returns an _Iter_pred ... why are the names reversed?
When you're in a long list of things called iter_comp_iter and
iter_comp_to_val and iter_less_iter and iter_that_iter_this_iter_val
the names are *really* important to understand what the code does.
We have three helper functions called __iter_comp_iter but one is
unary and two are binary. The unary one is used to wrap an arbitrary
binary comparison function (usually coming from user code) to produce
another binary function object, but the binary ones are only used with
our own internal __ops function objects and they bind an iterator to
the function object to produce a unary function object. Why do they
have the same name? The unary one should be called something like
"make indirect", because it transforms bool(T1,T2) into bool(T1*,T2*),
and the binary ones should be "bind second" because they combine
bool(T1*,T2*) and T2* to produce bool(T1*) (i.e. partial application).