C++ Logo

std-proposals

Advanced search

Re: FDL proposal: Function Dependent Lookup

From: Paco Arjonilla <pacoarjonilla_at_[hidden]>
Date: Fri, 25 Dec 2020 04:22:27 +0000 (UTC)
 Thank you for all your answers.
I can see how there are more problems than I thought of and how complicated it may become to specify, for the small advantage of removing a single using statement. Standardizing named keywords looks now to be more appropriate, but that is something that can already be done, sort of, with named initializers.
Anyway, thank you all for considering it.Paco

    En viernes, 25 de diciembre de 2020 2:58:04 GMT+9, Arthur O'Dwyer via Std-Proposals <std-proposals_at_[hidden]> escribió:
 
 On Thu, Dec 24, 2020 at 12:48 AM Paco Arjonilla via Std-Proposals <std-proposals_at_[hidden]> wrote:

Hi all,

I want to propose a variation to ADL that goes in the opposite direction. Instead of function lookup dependent on arguments, it would perform argument lookup dependant on the function. I will call it Function Dependent Lookup (FDL) from here on.


[Basically, make `A::f(x)` consider looking up `x` in associated namespaces of `A::f`.]
Besides the general shootdown you've been getting in this thread (which is certainly correct and reasonable, but maybe a little too "nonconstructive-proof" or "economists' $20 bill joke" for your liking) — here are some practical concerns you'd have to solve before you could turn this into a proposal.
(1) You seem to be proposing that "FDL" should kick in whenever the function name is found by qualified lookup, not when it's found by unqualified lookup. And maybe only if all the arguments are of the form `keyword=value`? What if those assignment expressions are parenthesized, e.g. `A::f((x=1))`?
(2) Are you proposing that "FDL" would apply only to function calls, and never when unqualified lookup finds a non-function? That is, what happens in namespace A { auto g = [](auto) {}; int x; } int main() { A::g(x=1); }
(3) What if unqualified lookup of `x` would have found a variable in the local scope? What if it would have found a lambda capture? What if it would have found a structured binding? namespace A { void f(int); int x; } int main() { int x = 1; A::f(x=2); }
(4) What if the function call is separated from the qualified lookup of `A::f`, e.g. by parentheses? This disables ADL; should it disable your "FDL"? (And if not: how are you going to prevent it from disabling FDL?) namespace A { void f(int); int x; } int main() { (A::f)(x=1); }
(5) Does your modified lookup apply only to "keywords" or also to the right-hand "value" side of each assignment expression? Does it apply to non-assignment expressions? Your example on Gitlab implies that the modified lookup should apply to right-hand sides: namespace A { struct Flag {} loose, tight; struct Arg { Arg& operator=(std::initializer_list<Flag>); } xy_views; void f(Arg); } int main() { A::f(xy_views={loose, tight}); }
So then what if I do something like this, Python-style? namespace A { struct Arg { Arg& operator=(int); } x; void f(Arg); } int main() { int x = 1; A::f(x=x); // calls Arg::operator=(const Arg&)?? }
Basically, if you want to go this route, you have to specify your answers to these problems. I predict that by the time you've specified those answers, you'll have decided this proposal isn't worth pursuing after all, because it's not going to provide any solution that's fit for your purpose.
–Arthur--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
  

Received on 2020-12-24 22:22:33