digitalmars.D - static if for array type templates
- Frank Benoit (33/33) Apr 15 2006 if compiled with -version=witharray it gives an error about:
- Oskar Linde (11/20) Apr 16 2006 [snip]
if compiled with -version=witharray it gives an error about: arithmetic/string type expected for value-parameter, not int[] But I have this static if... ? /**/ class C( T ){ /**/ /**/ T mValue; /**/ /**/ // not for array types /**/ static if( !is( T : T[] )){ /**/ /**/ template TCmp( T tCompConst ){ /**/ bool comp(){ /**/ return mValue > tCompConst; /**/ } /**/ } /**/ /**/ } /**/ /**/ } /**/ /**/ class C1 : C!( int ){ /**/ mixin TCmp!( 3 ); /**/ } /**/ /**/ version ( witharray ){ /**/ class C2 : C!( int[] ){ /**/ } /**/ } /**/ /**/ /**/ void main(){ /**/ } /**/
Apr 15 2006
In article <e1qo6h$2012$1 digitaldaemon.com>, Frank Benoit says...if compiled with -version=witharray it gives an error about: arithmetic/string type expected for value-parameter, not int[] But I have this static if... ? /**/ class C( T ){ /**/ /**/ T mValue; /**/ /**/ // not for array types /**/ static if( !is( T : T[] )){[snip] is-expressions does not behave in the same way as template argument specialization. The above code reads: true when T is implicitly convertible to T[] (never). Try something like this instead (untested): template ArrayType(T:T[]) { alias T ArrayType; } .. static if ( !is( ArrayType!(T) )) { /Oskar
Apr 16 2006