yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeFix use of variadic generics with [Differentiable]. (#8736)bedc3421c

master
981 B33 linesraw
1//TEST:INTERPRET(filecheck=CHECK):
2
3void printNumbers<each T>(expand each T args) where T == int
4{
5    // An single expression statement whose type will be `(void, void, ...)`.
6    // where each `void` is the result of evaluating expression `printf(...)` with
7    // each corresponding element in `args` passed as print operand.
8    //
9    expand printf("%d\n", each args);
10
11    // The above statement is equivalent to:
12    // ```
13    // (printf("%d\n", args[0]), printf("%d\n", args[1]), ..., printf("%d\n", args[n-1]));
14    // ```
15}
16void compute<each T>(expand each T args) where T == int
17{
18    // Maps every element in `args` to `elementValue + 1`, and forwards the
19    // new values as arguments to `printNumber`.
20    printNumbers(expand ((each args) + 1));
21
22    // The above statement is equivalent to:
23    // ```
24    // printNumber(args[0] + 1, args[1] + 1, ..., args[n-1] + 1);
25    // ```
26}
27void main()
28{
29    compute(1,2,3);
30    // CHECK: 2
31    // CHECK: 3
32    // CHECK: 4
33}