On 9/22/20 2:53 PM, Kasra Sadeghi wrote:
On Tuesday, 22 September 2020 at 21:36:48 UTC, Ali Çehreli wrote:
...
alias Value = Algebraic!(int, double, string, None);
...
void main() {
printValue([Value(4.5), Value("hello"), Value(42)]);
}
Thanks! Wish there was a less redundant syntax for the arrays.
Do you really need to write literal Value arrays? If not, you would
build a Value[] at runtime without seeing the syntax above.
Still, here is a function template that provides better syntax:
Value[] valueArray(Args...)(Args args) {
Value[] result;
foreach (arg; args) {
result ~= Value(arg);
}
return result;
}
void main() {
printValue(valueArray(4.5, "hello", 42));
}
Ali