I disagree that the lifted lambdas proposal solves the problem that
I'm trying to solve with constraints. I don't believe that it's a
general solution, and I don't think it ever will be. Not without
constraints (or concepts).
Solving this problem generally requires the compiler to synthesize an
expression involving the named overload set that is compatible with
the called function.
Suppose you have a bunch of functions with the same name and different
arguments:
bool f(int a);
bool f(int a, int b);
bool f(int a, int b, int c);
Easy to use:
f(0);
f(0, 0);
f(0, 0, 0);
But what if I try to use that as a lifted lambda?
sort(first, last, []f)
Which f is chosen? What expression is evaluated by sort()? The
specification actually seems to make the program ill-formed. Unless
I'm not reading it right.
Even better, what if *first refers to a type in a different namespace so
f(*first)
refers to none of the declarations above? How would []f work with ADL?
Not a big deal for the f's of the world, but significant if you're
writing []operator+ or []operator*.
The point of requiring constrained functions is that expected
signature can be deduced from that functions requirements. If sort()
requires that the function object support the syntax comp(x, y), then
the compiler can use that to synthesize a conforming expression that
follows the same rules as if you'd written:
sort(first, last, [](auto x, auto y) { f(x, y); }
Overload resolution rules will apply here just like they would at any
other point in the program.
So, yes... the feature requires that your functions are constrained.
But that gives us a general solution. Plus, I don't have to write [].
> Another think I would like to discuss is that, how should the []id (or in
> your case overloaded argument) behave in the case of the member functions.
> Example from your paper:
> T p = accumulate(list.begin(), list.end(), operator*);
> T p = accumulate(list.begin(), list.end(), [](T a, T b) -> T { return
> operator*(a, b); });
> suggest, that no operator* defined as the member of class T will be
> considered in this situation. I am right? If so would it apply only for
> build-in operators?
I'd forgotten that C++ doesn't really work the way I want. The
synthesized expression should be "a * b", but that's a special case
for named operators. I suppose we'll need special rewrite rules.
Andrew