Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1742

Show
Ignore:
Timestamp:
07/09/10 04:19:15 (14 years ago)
Author:
andrei
Message:

Defined hasElaborateCopyConstructor and hasElaborateAssign

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/traits.d

    r1722 r1742  
    11661166    static assert(!hasLocalAliasing!(S3)); 
    11671167 
    11681168    struct S4 { int a; shared Object b; } 
    11691169    static assert(!hasLocalAliasing!(S4)); 
    11701170    struct S5 { char[] a; } 
    11711171    static assert(hasLocalAliasing!(S5)); 
    11721172    struct S6 { shared char[] b; } 
    11731173    static assert(!hasLocalAliasing!(S6)); 
    11741174    struct S7 { float[3] vals; } 
    11751175    static assert(!hasLocalAliasing!(S7)); 
     1176} 
     1177 
     1178/** 
     1179 True if a type defines an elaborate copy constructor. Elaborate copy 
     1180 constructors are introduced by defining $(D this(this)) for a $(D 
     1181 struct). (Non-struct types do not have elaborate copy constructors.) 
     1182 */ 
     1183template hasElaborateCopyConstructor(T) 
     1184{ 
     1185    enum hasElaborateCopyConstructor = is(typeof(&T.__postblit)); 
     1186} 
     1187 
     1188unittest 
     1189{ 
     1190    static assert(!hasElaborateCopyConstructor!int); 
     1191    struct S 
     1192    { 
     1193        this(this) {} 
     1194    } 
     1195    static assert(hasElaborateCopyConstructor!S); 
     1196} 
     1197 
     1198/** 
     1199   True if a type defines an elaborate assignmentq. Elaborate 
     1200   assignments are introduced by defining $(D opAssign(typeof(this))) 
     1201   or $(D opAssign(ref typeof(this))) for a $(D struct). (Non-struct 
     1202   types do not have elaborate assignments.) 
     1203 */ 
     1204template hasElaborateAssign(T) 
     1205{ 
     1206    enum hasElaborateAssign = is(typeof(T.init.opAssign(T.init))); 
     1207} 
     1208 
     1209unittest 
     1210{ 
     1211    static assert(!hasElaborateAssign!int); 
     1212    struct S { void opAssign(S) {} } 
     1213    static assert(hasElaborateAssign!S); 
     1214    struct S1 { void opAssign(ref S1) {} } 
     1215    static assert(hasElaborateAssign!S1); 
     1216    struct S2 { void opAssign(S1) {} } 
     1217    static assert(!hasElaborateAssign!S2); 
    11761218} 
    11771219 
    11781220//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 
    11791221// Classes and Interfaces 
    11801222//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 
    11811223 
    11821224/*** 
    11831225 * Get a $(D_PARAM TypeTuple) of the base class and base interfaces of 
    11841226 * this class or interface. $(D_PARAM BaseTypeTuple!(Object)) returns 
    11851227 * the empty type tuple.