template auto instantiation when parameters empty
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 5 10:09:01 PDT 2016
On 5/5/16 6:50 PM, Erik Smith wrote:
>
> Alias works at the cost of adding a 2nd type name:
>
> alias Res = Resource!();
> auto res = Res.create
>
> The other problem is that the alias definition by itself instantiates,
> which I can't afford.
>
> I have createResource() now, it just doesn't fit well with the rest of
> the calling styles.
>
> There is also this approach, which might be slightly more idiomatic
>
> struct Resource(T) {}
> struct Policy {}
>
> auto create(alias T)() {
> T!Policy r;
> return r;
> }
>
> auto r = create!Resource;
I believe factory external IFTI functions are quite idiomatic. They are
all over phobos.
-Steve
More information about the Digitalmars-d-learn
mailing list