Thread overview
opDispatch forwarding and ifti
Feb 27, 2017
John Colvin
Feb 27, 2017
Stefan Koch
Feb 27, 2017
John Colvin
Feb 27, 2017
Stefan Koch
Feb 27, 2017
Adam D. Ruppe
Feb 27, 2017
Stefan Koch
Feb 27, 2017
Timon Gehr
February 27, 2017
Has anyone ever found a way to actually implement forwarding properly with opDispatch, such that it works for both general templates and also functions called using ifti (implicit function template instantiation)?

I've spent a day on it trying to improve std.typecons.Proxy to support this and it seems impossible.

The problem is to support this:

template X()
{
    alias X = int;
}

struct S0
{
    template A(T ...)
    {
        alias A = X;
    }

    template foo(T ...)
    {
        void foo(K)(K t) {}
    }
}

struct S1
{
    private S0 _s0;
    import std.typecons : Proxy;
    mixin Proxy!_s0;
}

unittest
{
    S1 s1;

    alias B0 = s1._s0.A!();
    static assert(is(B0!() == int));
    s1._s0.foo(3);

    alias B1 = s1.A!();
    static assert(is(B1!() == int));
    s1.foo(3);
}
February 27, 2017
On Monday, 27 February 2017 at 12:14:10 UTC, John Colvin wrote:
> Has anyone ever found a way to actually implement forwarding properly with opDispatch, such that it works for both general templates and also functions called using ifti (implicit function template instantiation)?
>

What is your actual usecase ?
You are aware that your trying to mix an runtime and a compile-time feature, yes ?

If it can be done then you will have to use CTFE and aliasSeqOf.
February 27, 2017
On Monday, 27 February 2017 at 12:22:02 UTC, Stefan Koch wrote:
> On Monday, 27 February 2017 at 12:14:10 UTC, John Colvin wrote:
>> Has anyone ever found a way to actually implement forwarding properly with opDispatch, such that it works for both general templates and also functions called using ifti (implicit function template instantiation)?
>>
>
> What is your actual usecase ?

I'm trying to make std.typecons.Proxy support more things correctly (e.g. template members, members that are aliases of types). I thought that was clear from the rest of my post.

> You are aware that your trying to mix an runtime and a compile-time feature, yes ?

Not quite sure what you mean there. What is a runtime feature here?

> If it can be done then you will have to use CTFE and aliasSeqOf.

The problem isn't with generating code (unless there's some very involved exhaustive solution I haven't thought of). How would you imagine I would use CTFE or aliasSeqOf to help here?
February 27, 2017
On Monday, 27 February 2017 at 13:17:21 UTC, John Colvin wrote:
> On Monday, 27 February 2017 at 12:22:02 UTC, Stefan Koch wrote:
>> On Monday, 27 February 2017 at 12:14:10 UTC, John Colvin wrote:
>>> Has anyone ever found a way to actually implement forwarding properly with opDispatch, such that it works for both general templates and also functions called using ifti (implicit function template instantiation)?
>>>
>>
>> What is your actual usecase ?
>
> I'm trying to make std.typecons.Proxy support more things correctly (e.g. template members, members that are aliases of types). I thought that was clear from the rest of my post.
>
>> You are aware that your trying to mix an runtime and a compile-time feature, yes ?
>
> Not quite sure what you mean there. What is a runtime feature here?
>
>> If it can be done then you will have to use CTFE and aliasSeqOf.
>
> The problem isn't with generating code (unless there's some very involved exhaustive solution I haven't thought of). How would you imagine I would use CTFE or aliasSeqOf to help here?

op-dispatch is a runtime feature.
It takes a string which is avilable at compile-time and passes it as a runtime parameter.
This runtime parameter can be used at ctfe if opDispatch is called at ctfe.
Then aliasSeqOf transforms it into a string-literal which can be used by templates.
February 27, 2017
On Monday, 27 February 2017 at 14:27:21 UTC, Stefan Koch wrote:
> op-dispatch is a runtime feature.
> It takes a string which is avilable at compile-time and passes it as a runtime parameter.

Completely false. It runs opDispatch!("the_string") which is totally compile time.
February 27, 2017
On Monday, 27 February 2017 at 14:34:05 UTC, Adam D. Ruppe wrote:
> On Monday, 27 February 2017 at 14:27:21 UTC, Stefan Koch wrote:
>> op-dispatch is a runtime feature.
>> It takes a string which is avilable at compile-time and passes it as a runtime parameter.
>
> Completely false. It runs opDispatch!("the_string") which is totally compile time.

Oh damn. Just lost my Street Cred :)
February 27, 2017
On 27.02.2017 13:14, John Colvin wrote:
> Has anyone ever found a way to actually implement forwarding properly
> with opDispatch, such that it works for both general templates and also
> functions called using ifti (implicit function template instantiation)?
>
> I've spent a day on it trying to improve std.typecons.Proxy to support
> this and it seems impossible.

One reason why your test case doesn't work is probably this compiler bug:

struct S1{
    template opDispatch(string op){
        template opDispatch(T...){
            static int x;
        }
    }
}

unittest{
    S1 s1,s2;
    alias B1 = s1.A!().x; // error
    s1.A!().x=2;          // ok
}

opDispatch seems to not be resolved when aliasing a symbol.