"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function
Liam McGillivray
yoshi.pit.link.mario at gmail.com
Tue Apr 9 00:48:01 UTC 2024
On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew
Cattermole wrote:
> ```d
> enum Value = (a, b) {
> return a + b;
> }(1, 2);
> ```
>
> This alone should be a CTFE only function.
>
> But if we want template parameters, we'd need to wrap it with
> the template.
>
> ```d
> template Value(int a, int b) {
> enum Value = () {
> return a + b;
> }();
> }
>
> int value = Value!(1, 2);
> ```
>
> Does that help?
I had to reread this a few times to get a sense of what this is.
I might have just got it. This is effectively a CTFE function for
generating a constant based on the sum of two numbers, right?
Doing `int value = Value!(1, 2);` would set `value` to 3, right?
I suppose this was a good new thing to learn, though I'm still
quite far from being able to construct a function from another
function using a template.
I suppose that if I wanted it to make a function from another
function, I may be able to do it in a template using some `static
foreach` to make arrays of function parameters, and then combine
them together without the use of strings, instead using
placeholders (aliases or whatever they'd be called) and maybe the
`tupleof` function. Am I headed in the right direction (if you
can understand my weak attempt to describe the direction I'm
thinking of going in)?
More information about the Digitalmars-d-learn
mailing list