Tuples, CTFE, and Sliding Template Arguments

zjh fqbqrr at 163.com
Sat Jan 13 02:14:55 UTC 2024


On Friday, 12 January 2024 at 22:35:54 UTC, Walter Bright wrote:

> Sliding Template Arguments
>
> Consider the following template:
>
> ```
> void pluto(string s)()
> {
>     pragma(msg, s);
> }
>


```d
void pluto(Args...)(Args args)
{
     exec!(args[0])(args[1 .. args.length]);
}
```
Like this, I think as long as the left side is known at compile 
time, we can directly add this feature!

```d
void pluto(string s, Args...)(string x = s, Args args){

}
```
I think if there is an `overloaded version`, then choose the 
overloaded version. If not, you can simply slide it because there 
are usually `no side effects`, but there should be a method to 
determine whether the variable is known or unknown` at compile 
time`.

  I found out earlier that we can create an `attribute 
dictionary`. `Functions/variables/etc...` can all have an 
`attribute dictionary`.

Here, if 'x' has an attribute dictionary, it can extract 
information that if `'x'` is a compile time variable.

So, you can use this information for `compile time 
metaprogramming`!

Moreover, try to `deduct` the function's attribute dictionary as 
much as possible. This way, there is no need for each function's 
endless attribute soup.



More information about the Digitalmars-d mailing list