Changeset 2019
- Timestamp:
- 09/17/10 23:43:54 (14 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/traits.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r2018 r2019 10 10 $(UL $(LI Tuple members are now accessible with the syntax a[0], a[1] etc.) 11 11 $(LI Eliminated an internal union. See $(BUGZILLA 4421) and $(BUGZILLA 4846).) 12 12 $(LI Worked around $(BUGZILLA 4424). Got opAssign back.) 13 13 $(LI Made Tuple.slice!(from, to) to preserve field names if any.) 14 14 $(LI Added isTuple!(T) template.) 15 15 )) 16 16 ) 17 17 $(BUGSFIXED 18 18 $(LI Unlisted bug: std.exception.pointsTo() calls postblit on subobjects.) 19 19 $(LI Unlisted bug: std.typetuple.staticMap!() doesn't work with empty/single tuples.) 20 $(LI Unlisted bug: std.traits: Interfaces should have indirections, aliasing, etc.) 21 $(LI 4882: std.traits hasUnsharedAliasing does not work for function type.) 20 22 ) 21 23 ) 22 24 23 25 24 26 <div id=version> 25 27 $(UL 26 28 $(NEW 049) 27 29 $(NEW 048) 28 30 $(NEW 047) 29 31 $(NEW 046) trunk/phobos/std/traits.d
r2008 r2019 937 937 // hasRawAliasing 938 938 939 939 private template hasRawPointerImpl(T...) 940 940 { 941 941 static if (T.length == 0) 942 942 { 943 943 enum result = false; 944 944 } 945 945 else 946 946 { 947 static if (is(T[0] foo : U*, U) )947 static if (is(T[0] foo : U*, U) && !isFunctionPointer!(T[0])) 948 948 enum hasRawAliasing = !is(U == immutable); 949 949 else static if (is(T[0] foo : U[], U) && !isStaticArray!(T[0])) 950 950 enum hasRawAliasing = !is(U == immutable); 951 951 else static if (isAssociativeArray!(T[0])) 952 952 enum hasRawAliasing = !is(T[0] == immutable); 953 953 else 954 954 enum hasRawAliasing = false; 955 955 enum result = hasRawAliasing || hasRawPointerImpl!(T[1 .. $]).result; 956 956 } 957 957 } 958 958 959 959 private template HasRawLocalPointerImpl(T...) 960 960 { 961 961 static if (T.length == 0) 962 962 { 963 963 enum result = false; 964 964 } 965 965 else 966 966 { 967 static if (is(T[0] foo : U*, U) )967 static if (is(T[0] foo : U*, U) && !isFunctionPointer!(T[0])) 968 968 enum hasRawLocalAliasing = !is(U == immutable) && !is(U == shared); 969 969 else static if (is(T[0] foo : U[], U) && !isStaticArray!(T[0])) 970 970 enum hasRawLocalAliasing = !is(U == immutable) && !is(U == shared); 971 971 else static if (isAssociativeArray!(T[0])) 972 972 enum hasRawLocalAliasing = !is(T[0] == immutable) && !is(T[0] == shared); 973 973 else 974 974 enum hasRawLocalAliasing = false; 975 975 enum result = hasRawLocalAliasing || HasRawLocalPointerImpl!(T[1 .. $]).result; 976 976 } 977 977 } … … 1150 1150 { 1151 1151 enum hasObjects = hasObjects!(U, T[1 .. $]); 1152 1152 } 1153 1153 else static if (is(T[0] == struct)) 1154 1154 { 1155 1155 enum hasObjects = hasObjects!( 1156 1156 RepresentationTypeTuple!(T[0]), T[1 .. $]); 1157 1157 } 1158 1158 else 1159 1159 { 1160 enum hasObjects = ( is(T[0] == class) && !is(T[0] == immutable)) ||1161 hasObjects!(T[1 .. $]);1160 enum hasObjects = ((is(T[0] == class) || is(T[0] == interface)) 1161 && !is(T[0] == immutable)) || hasObjects!(T[1 .. $]); 1162 1162 } 1163 1163 } 1164 1164 1165 1165 /* 1166 1166 Statically evaluates to $(D true) if and only if $(D T)'s 1167 1167 representation includes at least one non-immutable non-shared object 1168 1168 reference. 1169 1169 */ 1170 1170 1171 1171 private template hasUnsharedObjects(T...) … … 1178 1178 { 1179 1179 enum hasUnsharedObjects = hasUnsharedObjects!(U, T[1 .. $]); 1180 1180 } 1181 1181 else static if (is(T[0] == struct)) 1182 1182 { 1183 1183 enum hasUnsharedObjects = hasUnsharedObjects!( 1184 1184 RepresentationTypeTuple!(T[0]), T[1 .. $]); 1185 1185 } 1186 1186 else 1187 1187 { 1188 enum hasUnsharedObjects = ( is(T[0] == class) &&1188 enum hasUnsharedObjects = ((is(T[0] == class) || is(T[0] == interface)) && 1189 1189 !is(T[0] == immutable) && !is(T[0] == shared)) || 1190 1190 hasUnsharedObjects!(T[1 .. $]); 1191 1191 } 1192 1192 } 1193 1193 1194 1194 /** 1195 1195 Returns $(D true) if and only if $(D T)'s representation includes at 1196 1196 least one of the following: $(OL $(LI a raw pointer $(D U*) and $(D U) 1197 1197 is not immutable;) $(LI an array $(D U[]) and $(D U) is not 1198 immutable;) $(LI a reference to a class type $(D C) and $(D C) is not1199 immutable.) $(LI an associative array that is not immutable.)1198 immutable;) $(LI a reference to a class or interface type $(D C) and $(D C) is 1199 not immutable.) $(LI an associative array that is not immutable.) 1200 1200 $(LI a delegate.)) 1201 1201 */ 1202 1202 1203 1203 template hasAliasing(T...) 1204 1204 { 1205 1205 enum hasAliasing = hasRawAliasing!(T) || hasObjects!(T) || 1206 1206 anySatisfy!(isDelegate, T); 1207 1207 } 1208 1208 1209 1209 unittest … … 1212 1212 static assert(hasAliasing!(S1)); 1213 1213 struct S2 { string a; } 1214 1214 static assert(!hasAliasing!(S2)); 1215 1215 struct S3 { int a; immutable Object b; } 1216 1216 static assert(!hasAliasing!(S3)); 1217 1217 struct X { float[3] vals; } 1218 1218 static assert(!hasAliasing!X); 1219 1219 static assert(hasAliasing!(uint[uint])); 1220 1220 static assert(!hasAliasing!(immutable(uint[uint]))); 1221 1221 static assert(hasAliasing!(void delegate())); 1222 static assert(!hasAliasing!(void function())); 1223 1224 interface I; 1225 static assert(hasAliasing!I); 1222 1226 } 1223 1227 1224 1228 /** 1225 1229 Returns $(D true) if and only if $(D T)'s representation includes at 1226 1230 least one of the following: $(OL $(LI a raw pointer $(D U*);) $(LI an 1227 1231 array $(D U[]);) $(LI a reference to a class type $(D C).) 1228 1232 $(LI an associative array.) $(LI a delegate.)) 1229 1233 */ 1230 1234 1231 1235 template hasIndirections(T) 1232 1236 { 1233 1237 enum hasIndirections = hasIndirectionsImpl!(RepresentationTypeTuple!T); 1234 1238 } 1235 1239 1236 1240 template hasIndirectionsImpl(T...) 1237 1241 { 1238 1242 static if (!T.length) 1239 1243 { 1240 1244 enum hasIndirectionsImpl = false; 1241 1245 } 1246 else static if(isFunctionPointer!(T[0])) 1247 { 1248 enum hasIndirectionsImpl = hasIndirectionsImpl!(T[1 .. $]); 1249 } 1242 1250 else 1243 1251 { 1244 1252 enum hasIndirectionsImpl = isPointer!(T[0]) || isDynamicArray!(T[0]) || 1245 1253 is (T[0] : const(Object)) || isAssociativeArray!(T[0]) || 1246 isDelegate!(T[0]) || hasIndirectionsImpl!(T[1 .. $]); 1254 isDelegate!(T[0]) || is(T[0] == interface) 1255 || hasIndirectionsImpl!(T[1 .. $]); 1247 1256 } 1248 1257 } 1249 1258 1250 1259 unittest 1251 1260 { 1252 1261 struct S1 { int a; Object b; } 1253 1262 static assert(hasIndirections!(S1)); 1254 1263 struct S2 { string a; } 1255 1264 static assert(hasIndirections!(S2)); 1256 1265 struct S3 { int a; immutable Object b; } 1257 1266 static assert(hasIndirections!(S3)); 1258 1267 static assert(hasIndirections!(int[string])); 1259 1268 static assert(hasIndirections!(void delegate())); 1269 1270 interface I; 1271 static assert(hasIndirections!I); 1272 static assert(!hasIndirections!(void function())); 1260 1273 } 1261 1274 1262 1275 // These are for backwards compatibility, are intentionally lacking ddoc, 1263 1276 // and should eventually be deprecated. 1264 1277 alias hasUnsharedAliasing hasLocalAliasing; 1265 1278 alias hasRawUnsharedAliasing hasRawLocalAliasing; 1266 1279 alias hasUnsharedObjects hasLocalObjects; 1267 1280 1268 1281 /** 1269 1282 Returns $(D true) if and only if $(D T)'s representation includes at … … 1299 1312 struct S5 { char[] a; } 1300 1313 static assert(hasUnsharedAliasing!(S5)); 1301 1314 struct S6 { shared char[] b; } 1302 1315 static assert(!hasUnsharedAliasing!(S6)); 1303 1316 struct S7 { float[3] vals; } 1304 1317 static assert(!hasUnsharedAliasing!(S7)); 1305 1318 1306 1319 static assert(hasUnsharedAliasing!(uint[uint])); 1307 1320 static assert(hasUnsharedAliasing!(void delegate())); 1308 1321 static assert(!hasUnsharedAliasing!(shared(void delegate()))); 1322 static assert(!hasUnsharedAliasing!(void function())); 1323 1324 interface I {} 1325 static assert(hasUnsharedAliasing!I); 1309 1326 } 1310 1327 1311 1328 /** 1312 1329 True if $(D S) or any type embedded directly in the representation of $(D S) 1313 1330 defines an elaborate copy constructor. Elaborate copy constructors are 1314 1331 introduced by defining $(D this(this)) for a $(D struct). (Non-struct types 1315 1332 never have elaborate copy constructors.) 1316 1333 */ 1317 1334 template hasElaborateCopyConstructor(S) 1318 1335 {
