C++ Logo

std-proposals

Advanced search

Re: FDL proposal: Function Dependent Lookup

From: connor horman <chorman64_at_[hidden]>
Date: Thu, 24 Dec 2020 09:09:56 -0500
I can see this being *very *annoying to implement.

On Thu, Dec 24, 2020 at 00:48 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.
>
> For example,
>
> ```
> namespace A {
> constexpr int x = 1;
> void f(int);
> }
> int main() {
> A::f(x);
> }
> ```
>
> With the current C++ standard, the above code does not compile. To fix it,
> we can either indicate the namespace for x
> ```
> int main() {
> A::f(A::x);
> }
> ```
> or add a using statement.
> ```
> int main() {
> using namespace A;
> A::f(x);
> }
> ```
>
> The motivation for the proposal is to enable named keyword arguments
> without polluting the scope. Keyword arguments are possible by overloading
> operator = and using several auxiliar classes. For example, consider the
> following model snippet
>
> ```
> void foo() {
> matrixlib::matrix_t data = matrixlib::load("/Path/to/training/data");
>
> // using namespace nnlib; /* This line is necessary, but it pollutes
> the scope with the identifiers of all
> named keywords! */
> auto trained_nn = nnlib::train_deep_neural_network(
> data,
> hidden_layers=2,
> learning_rate=0.09,
> momentum=0.9,
> maximum_epochs=100000,
> acceptable_error=10e-5
> );
>
> ...
> }
> ```
>
> FDL would enable using C++ function calls with python-like syntax without
> polluting the scope. It would make easier for users of python and other
> languages to migrate to C++ and to write libraries in C++ with similar
> syntax. Neural Network libraries is a typical example.
>
>
> Possible ambiguity resolution with ADL:
> To avoid ambiguities with ADL and make FDL compatible with ADL, FDL would
> only be enabled when the function is called with a scope resolution, i.e.
> `scope::function(keyword=value);`
>
>
> For a working use case, see the experimental library namiplot.
>
> namiplot.gitlab.io
>
> Namiplot uses named keywords to set graphic parameters in order to plot
> data. Compilation tested with GCC10. Specifically, FDL would be
> advantageous in the working example at:
>
>
> https://gitlab.com/namiplot/namiplot/-/blob/master/examples/data_types/functions.cc
>
>
> Thank you for reading this far!
>
> Cheers
> Paco
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-12-24 08:10:16