Strange Mixin issue

Frustrated Frustrated at nowhere.com
Wed Mar 5 14:37:35 PST 2014


On Wednesday, 5 March 2014 at 22:35:46 UTC, Ali Çehreli wrote:
> On 03/05/2014 01:30 PM, Frustrated wrote:
>> I am trying to remove the unnecessary passing of the type of 
>> class to a
>> template but can't seem to get it to work:
>>
>> see
>>
>>
>>
>> The code is the
>>
>>
>>     mixin(AbstractToInterface!(WindowsGui, iButton, 
>> WindowsButton,
>> iBorder, WindowsBorder));
>>
>> which I want to not have to specify WindowsGui.
>>
>> I've tried wrapping AbstractToInterface in a mixin template 
>> and use that
>> and typeof(this) but then the mixin of the mixin does not get 
>> mixed in
>> to the class
>>
>> e.g.,
>>
>> mixin template AbstractToInterface2(T...)
>> {
>>     mixin(AbstractToInterface!(typeof(this), T));
>> }
>>
>> Then use mixin AbstractTointerface2!(iButton, WindowsButton, 
>> iBorder,
>> WindowsBorder).
>>
>> It's probably something stupid but I can't seem to get it to 
>> work(have a
>> very similar case in some other code and it works fine... the 
>> only
>> difference is I'm not using nested mixins.
>>
>
> The following works for me maybe because the templates are not 
> mixin templates. What's a mixin template again?
>
> import std.typetuple;
>
> template fooImpl(This, T...)
> {
>     static assert(is (This == S));        // <-- IT WORKED!
>     static assert(is (T == TypeTuple!(int, double)));
> }
>
> template foo(T...)
> {
>     alias foo = fooImpl!(typeof(this), T);
> }
>
> struct S
> {
>     mixin foo!(int, double);
> }
>
> void main()
> {
>     auto s = S();
> }
>
> Even better:
>
> import std.typetuple;
>
> template fooImpl(T...)
> {
>     static assert(is (T[0] == S));    // <-- COOL!
>     static assert(is (T[1] == int));
>     static assert(is (T[2] == double));
> }
>
> template foo(T...)
> {
>     alias foo = fooImpl!(TypeTuple!(typeof(this), T));
> }
>
> struct S
> {
>     mixin foo!(int, double);
> }
>
> void main()
> {
>     auto s = S();
> }
>
> Ali

this is not quite the same. You have static asserts. I'm trying 
to avoid mixing in ctfe code that might interfer with the class. 
(I have a temp function Do which if I mixin as a normal template 
will mixin Do into the class make Do a member of that class)



More information about the Digitalmars-d-learn mailing list