www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - static if for array type templates

reply Frank Benoit <keinfarbton nospam.xyz> writes:
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
parent Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
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