"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function
Liam McGillivray
yoshi.pit.link.mario at gmail.com
Mon Apr 8 23:42:37 UTC 2024
On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew
Cattermole wrote:
>>> ```d
>>> template Foo(Args) {
>>> enum Foo = () {
>>> return Args.init;
>>> }();
>>> }
>>> ```
>>>
>>> Something like that should work instead.
>>
>> I'm sorry, but I can't comprehend any of your example. What
>> would be fed into `Args`? I don't understand how this works,
>> or how I would use it for what I want.
>
> You would replace it with whatever template parameters you want
> (including nothing). It's there as a place holder.
>
> Same for the return on the closure.
>
> But the main thing to understand is that the closure that gives
> the enum a value, that'll be CTFE only, no runtime target.
Are you saying that this is a way to guarantee that the code is
compile-time only?
I still understand very little of this code. I'm not experienced
in D metaprogramming; just the function I posted above was a
major achievement for me. I don't understand how I would use the
code you gave in place of the function I have written and posted
above.
When you say that "You would replace it with whatever template
parameters you want", are you saying that instead of doing
`mixin(MakeStringOverload!SetWindowTitle);
mixin(MakeStringOverload!LoadShader);` as posted above, I would
write `mixin(Foo!(SetWindowTitle, LoadShader));`?
What does the `return Args.init;` line mean in your example? Am I
supposed to replace this with a call to the CTFE function I had
already written? If so, it didn't work. Making such a replacement
resulted in the same "TypeInfo" error that I had already.
More information about the Digitalmars-d-learn
mailing list