Is there a better way to do this? (Using class at compile-time)
bauss
jj_1337 at live.dk
Tue Jun 12 12:17:18 UTC 2018
On Tuesday, 12 June 2018 at 11:18:00 UTC, Simen Kjærås wrote:
> On Tuesday, 12 June 2018 at 11:04:40 UTC, bauss wrote:
> [snip]
>> void test(T)()
>> {
>> pragma(msg, (getBar!T).baz());
>> pragma(msg, (getBar!T).helloworld());
>>
>> import std.stdio;
>>
>> mixin((getBar!T).baz());
>> mixin((getBar!T).helloworld());
>> }
> [snip]
>> Is there a way to avoid having to write "getBar!T" every time
>> since we cannot store a class into a compile-time variable,
>> how would one avoid such thing?
>
> static const instance = new Bar!T;
> enum text1 = b.baz();
> enum text2 = b.helloworld();
>
> However, since it's a const instance, you'll only be able to
> call const methods on it, and you'll need to mark baz and
> helloworld as const.
>
> --
> Simen
Thanks, that might work way better!
My situation is a little different than what my example showed,
but I should be able to get it working with static const.
More information about the Digitalmars-d-learn
mailing list