digitalmars.D.learn - How do you peek a variant containing a complex value?
- Vinay Sajip (15/15) Feb 22 2020 The following program won't compile if I uncomment the if
- nullptr (14/29) Feb 22 2020 The type in v isn't Complex, it's Complex!double.
- Vinay Sajip (2/3) Feb 23 2020 Ah, great. Thanks! Missed that.
The following program won't compile if I uncomment the if statement: void main() { Variant v = complex(1.0, 1.0); // if (v.peek!(Complex)) { // writeln("Complex"); // } writeln(v); } I get the same error with v.peek!(complex), which is: Error: template instance peek!(Complex) does not match template declaration peek(T)() The variant can clearly hold a complex value. Someone please tell me - what am I doing wrong in the peek call?
Feb 22 2020
On Saturday, 22 February 2020 at 18:00:16 UTC, Vinay Sajip wrote:The following program won't compile if I uncomment the if statement: void main() { Variant v = complex(1.0, 1.0); // if (v.peek!(Complex)) { // writeln("Complex"); // } writeln(v); } I get the same error with v.peek!(complex), which is: Error: template instance peek!(Complex) does not match template declaration peek(T)() The variant can clearly hold a complex value. Someone please tell me - what am I doing wrong in the peek call?The type in v isn't Complex, it's Complex!double. This will work the way you want: ``` void main() { Variant v = complex(1.0, 1.0); if (v.peek!(Complex!double)) { writeln("Complex"); } writeln(v); } ```
Feb 22 2020
On Saturday, 22 February 2020 at 18:32:06 UTC, nullptr wrote:The type in v isn't Complex, it's Complex!double.Ah, great. Thanks! Missed that.
Feb 23 2020