On Monday, October 19, 2015 04:51 PM, Stewart Moth wrote: > struct Vector(type, int dimension_){ ... } > > Where type is going to be an int/float/etc and dimension_ is > 2/3/4. > > I could write a bunch of functions for each case, but I'd rather > not... I'd like to use something like the following: > > void foo(T)(Array!T array){ > if(isInstanceOf!(Vector, T)){ > //get type of T or check it > //test if dimension_ is 2 or 3 or 4 > ... > } else { > //Non-vector stuff > ... > } > } > > But to do that I need to check that parameters of T as if it were > an instantiated instance of Vector and I'm not sure how to > accomplish that... Can anyone help me out with what I need to do?
You can use std.traits.TemplateArgsOf: ---- static if(isInstanceOf!(Vector, T)){ /* note: must be a static if */ enum dimensions = TemplateArgsOf!T[1]; static if(dimensions == 2) {...} } ----