Changeset 1756
- Timestamp:
- 07/14/10 01:17:00 (14 years ago)
- Files:
-
- trunk/phobos/std/traits.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/traits.d
r1742 r1756 1208 1208 1209 1209 unittest 1210 1210 { 1211 1211 static assert(!hasElaborateAssign!int); 1212 1212 struct S { void opAssign(S) {} } 1213 1213 static assert(hasElaborateAssign!S); 1214 1214 struct S1 { void opAssign(ref S1) {} } 1215 1215 static assert(hasElaborateAssign!S1); 1216 1216 struct S2 { void opAssign(S1) {} } 1217 1217 static assert(!hasElaborateAssign!S2); 1218 } 1219 1220 /** 1221 Yields $(D true) if and only if $(D T) is a $(D struct) or a $(D 1222 class) that defines a symbol called $(D name). 1223 */ 1224 template hasMember(T, string name) 1225 { 1226 static if (is(T == struct) || is(T == class)) 1227 { 1228 enum bool hasMember = 1229 staticIndexOf!(name, __traits(allMembers, T)) != -1; 1230 } 1231 else 1232 { 1233 enum bool hasMember = false; 1234 } 1235 } 1236 1237 unittest 1238 { 1239 //pragma(msg, __traits(allMembers, void delegate())); 1240 static assert(!hasMember!(int, "blah")); 1241 struct S1 { int blah; } 1242 static assert(hasMember!(S1, "blah")); 1243 struct S2 { int blah(); } 1244 static assert(hasMember!(S2, "blah")); 1245 struct C1 { int blah; } 1246 static assert(hasMember!(C1, "blah")); 1247 struct C2 { int blah(); } 1248 static assert(hasMember!(C2, "blah")); 1218 1249 } 1219 1250 1220 1251 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 1221 1252 // Classes and Interfaces 1222 1253 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 1223 1254 1224 1255 /*** 1225 1256 * Get a $(D_PARAM TypeTuple) of the base class and base interfaces of 1226 1257 * this class or interface. $(D_PARAM BaseTypeTuple!(Object)) returns 1227 1258 * the empty type tuple.
