On Tuesday, 10 March 2015 at 10:27:14 UTC, John Colvin wrote:
struct S
{
        int a;
        this(T)(T v)
        {
                this = v;
        }
        void foo(T)(T v)
        {
                import std.conv : to;
                a = v.to!int;
        }
        alias foo this;
}

void bar(S s){}

void main()
{
        S s0;
        s0 = "3"; //OK
        S s = "3"; //OK
        bar("3"); //Not OK
}

It would seem logical that the last one would work as well. What's the reasoning behind this?

Do you think that the parameter should be automatically created from the argument ? Is this kind of thing even possible in another context ?

Your alias looks more like an ```opCall()```. To my eyes the strange thing is that if you add the following statement at the end of you sample:
---
s(0);
---

DMD outputs:

```Error: cannot resolve type for s.foo(T)(T v)```

Reply via email to