Array of Algebraic argument syntax

Ali Çehreli acehreli at yahoo.com
Tue Sep 22 21:36:48 UTC 2020


On 9/22/20 2:30 PM, Kasra Sadeghi wrote:
> Hi everyone!
> 
> What's the syntax for passing an array of Algebraics?
> 
> definition:
> 
>   class None {}
>   class Value = Algebraic!(int, double, string, None);

That should be 'alias' instead of 'class':

import std.variant;
import std.stdio;

class None {}
alias Value = Algebraic!(int, double, string, None);

void printValue(Value[] values) {
   foreach(value; values) {
     value.writeln;
   }
}

void main() {
   printValue([Value(4.5), Value("hello"), Value(42)]);
}

Ali



More information about the Digitalmars-d-learn mailing list