#Create comptime type

1 messages · Page 1 of 1 (latest)

vale hamlet
#

Hello All,
I am creating a toy program for complex number struct which I want to instantiate only for f32 and f64. For e.g.

pub fn Complex(comptime T: type) type { // Add code to only allow creating this type for f32 and f64 i.e. do compile error when someone tries to create this type for u8 etc. return Struct { // Value and code for complex number like abs, arg, angle etc. ... }; }

How to achieve this?

Thanks
Ashutosh

lunar silo
#

You can do something like

if (T != f32 and T != f64) @compileError("T must be a f32 or a f64");