Constuctor supporting direcs assigment of Type
Forwards call to union member Works only if all union members has this function and this function has the same return type and parameter types Can not be made opDispatch because it somehow breakes hasMember trait
Support for serialization
returns given type with check
Returns enum value for Type
Sets given Type
Preety print
Checks if opDispatch supports given function
Returns enum value for Type
Example Usage
t { struct Triangle { int add(int a) { return a + 10; } } struct Rectangle { int add(int a) { return a + 100; } } static uint strangeID(T)(T obj) { static if (is(T == Triangle)) { return 123; } else static if (is(T == Rectangle)) { return 14342; } else { assert(0); } } alias Shape = SafeUnion!(false, Triangle, Rectangle); Shape shp; shp.set(Triangle()); assert(shp.isType!Triangle); assert(!shp.isType!Rectangle); assert(shp.call!("add")(6) == 16); //Better error messages assert(shp.apply!strangeID == 123); //shp.get!(Rectangle);//Crash shp.set(Rectangle()); assert(shp.call!("add")(6) == 106); assert(shp.apply!strangeID == 14342); shp.currentType = shp.Types.none; //shp.apply!strangeID;//Crash //shp.add(6);//Crash final switch (shp.currentType) { case shp.getEnum!Triangle: break; case Shape.getEnum!Rectangle: break; case Shape.Types.none: break;
Union of ConTypes... Ensures correct access with assert