On Monday, 23 April 2018 at 17:46:10 UTC, Arafel wrote:

You could also argue that function overloads are just semantically equivalent to a single function with variadic arguments.

It is not. As there are exact known, distinct, finite numbers and types of arguments of functions, which can be used. For example, zero and one.

So:

void foo(){}
void foo(int){}

How this is achievable with variadic functions?

Whether the compiler actually lowers it like that or not should be just an implementation detail, and thus simply not relevant.

Right.


And from a syntactical point of view, it wouldn't make any sense if the following "overloads" were treated differently:

```
class A {
    @("int", "odd")
        template Foo1(int N) if (N & 1)    {
        enum Foo1 = "A";
    }
    @("int", "even")
        template Foo1(int N) if (!(N & 1))    {
        enum Foo1 = "B";
    }
    @("string", "+")
        template Foo1(string op) if (op == "+") {
        enum Foo1 = "C";
    }
    @("multi", "string")
template Foo1(T...) if (allSatisfy!(isSomeString, typeof(T)) && T.length > 1) {
        enum Foo1 = "D";
    }
    @("multi", "double")
template Foo1(T...) if (allSatisfy!(isFloatingPoint, typeof(T)) && T.length > 1) {
        enum Foo1 = "E";
    }
}
```

So, in my opinion, a callable object is overloaded, when there exist more then one interface how to call it.

Before a template is instantiated, no callable objects exist.

Now, you can go on say well, a template defines a family of objects, which build up an overload set. This is not doable, see the discussion before.

But of course, you can go the other way and say well, if there exist a declaration then, based on the declaration inspection, let us define an overload set, based on the same symbol names.

This is a different way of defining an overload, which is not obvious, especially if you see the pragma output from a former post. Therein the pragmas, which act also before runtime do not differ between declarations, but only between instantiations.

Reply via email to