new properties for basic types

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 14 22:26:49 PDT 2014


> Hmm.
> So how do I use stuff like this:
>
>     template defaultInit(T)
>     {
>         static if (!is(typeof({ T v = void; })))    // inout(U)
>             @property T defaultInit(T v = T.init);
>         else
>             @property T defaultInit();
>     }
>
> (this is from std.traits - ok, it's private, but anyway)

It should be invoked as `defaultInit!SomeType`


> Because I have seen nowhere anything like defaultInit!T (or T.defaultInit)
> and don't understand why here the attribute @property is used.
> Why does it make a difference, and how?

@property allows you to call a function without the parenthesis (), to
imitate a field in a struct or class.
In this particular case, I don't know what defaultInit is used for. It
seems to compile to a forward declaration of a function, but I don't
know what for.

I cannot find it on my copy of std.traits. What DMD version are you using?


More information about the Digitalmars-d-learn mailing list