qualified type names for mixins
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 15 15:36:56 PDT 2017
On Thursday, 15 June 2017 at 21:54:44 UTC, Adam D. Ruppe wrote:
> On Thursday, 15 June 2017 at 21:26:38 UTC, Jonathan Marler
> wrote:
>> The common use case is when you'd like to mixin a type when it
>> is passed to a template.
>
> That's also the most common wrong case. If it is passed to a
> template, you have a local name that you should use because it
> will work despite import or privacy restrictions that would
> break with the full name. So....
Doesn't work with eponymous templates, like std.traits.Flag. For
example, make this code work:
import std.stdio, std.traits;
template TypeWrapper(T)
{
alias TypeWrapper = T;
}
void main()
{
writefln(TypeWrapper!bool.stringof); // Works
writefln(TypeWrapper!(Flag!"yes").stringof); // Doesn't work
}
>
>> It uses T.stringof in some cases
>
> ...just use T. Drop the stringof and you'll find it much easier
> and correct.
When you mixin the type, you need a "string', T is not a string,
it's an alias to a type.
More information about the Digitalmars-d
mailing list