Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3898

Show
Ignore:
Timestamp:
08/20/08 14:07:55 (4 months ago)
Author:
larsivi
Message:

Make Variant use Traits where applicable, fixes broken unittest and removes some duplication.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/core/Variant.d

    r3810 r3898  
    99 
    1010private import tango.core.Vararg : va_list; 
     11private import tango.core.Traits; 
    1112 
    1213private 
     
    7172    } 
    7273 
    73     template isArray(T) 
    74     { 
    75         static if( is( T U : U[] ) ) 
    76             const isArray = true; 
    77         else 
    78             const isArray = false; 
    79     } 
    80  
    81     template isPointer(T) 
    82     { 
    83         static if( is( T U : U* ) ) 
    84             const isPointer = true; 
    85         else 
    86             const isPointer = false; 
    87     } 
    88  
    8974    template isObject(T) 
    9075    { 
     
    10186        else 
    10287            const isInterface = false; 
    103     } 
    104  
    105     template isStaticArray(T) 
    106     { 
    107         static if( is( typeof(T.init)[(T).sizeof / typeof(T.init).sizeof] == T ) ) 
    108             const isStaticArray = true; 
    109         else 
    110             const isStaticArray = false; 
    11188    } 
    11289 
     
    194171    template storageT(T) 
    195172    { 
    196         static if( isStaticArray!(T) ) 
     173        static if( isStaticArrayType!(T) ) 
    197174            alias typeof(T.dup) storageT; 
    198175        else 
     
    241218        Variant _this; 
    242219 
    243         static if( isStaticArray!(T) ) 
     220        static if( isStaticArrayType!(T) ) 
    244221            _this = value.dup; 
    245222 
     
    262239    Variant opAssign(T)(T value) 
    263240    { 
    264         static if( isStaticArray!(T) ) 
     241        static if( isStaticArrayType!(T) ) 
    265242        { 
    266243            return (*this = value.dup); 
     
    274251                mixin("this.value._"~T.stringof~"=value;"); 
    275252            } 
    276             else static if( isArray!(T) ) 
     253            else static if( isDynamicArrayType!(T) ) 
    277254            { 
    278255                this.value.arr = (cast(void*)value.ptr) 
    279256                    [0 .. value.length]; 
    280257            } 
    281             else static if( isPointer!(T) ) 
     258            else static if( isPointerType!(T) ) 
    282259            { 
    283260                this.value.ptr = cast(void*)value; 
     
    414391            } 
    415392        } 
    416         else static if( isArray!(T) ) 
     393        else static if( isDynamicArrayType!(T) ) 
    417394        { 
    418395            return (cast(typeof(T[0])*)this.value.arr.ptr) 
    419396                [0 .. this.value.arr.length]; 
    420397        } 
    421         else static if( isPointer!(T) ) 
     398        else static if( isPointerType!(T) ) 
    422399        { 
    423400            return cast(T)this.value.ptr;