April 15, 2006 static if for array type templates | ||||
---|---|---|---|---|
| ||||
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(){ /**/ } /**/ |
April 16, 2006 Re: static if for array type templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | 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 |
Copyright © 1999-2021 by the D Language Foundation