Tuples, CTFE, and Sliding Template Arguments

Daniel N no at public.email
Sat Jan 13 18:32:29 UTC 2024


On Friday, 12 January 2024 at 22:35:54 UTC, Walter Bright wrote:
> Given the interest in CTFE of istrings, I have been thinking 
> about making a general use case out of it instead of one 
> specific to istrings.
> ---------------------
> ```
> But notice that `args` are runtime arguments. It turns out 
> there is no way
> to use tuples to split an argument tuple into compile time and 
> runtime tuples:
>
> ```
> void pluto(Args...)(Args args)
> {
>     exec!(args[0])(args[1 .. args.length]);
> }
> ```

What if you split the type-tuple instead but store a value at [0].

```d

import std.stdio;

// Works today!
void pluto_v1(Args...)(string, Args[1] a1, Args[2] a2)
{
     pragma(msg, Args[0]); // Compile-time value!
}

// Almost compiles... add 'void' to explicitly slide instead of 
implicit magic.
void pluto_v2(Args...)(void, Args[1..$] args)
{
     pragma(msg, Args[0]); // Compile-time value!
     args.writeln;
}

void main()
{
     pluto_v1!("x", int, int)("x", 2, 3);
//  pluto_v2("x", 2, 3);
}
  ```



More information about the Digitalmars-d mailing list