Changeset 1964
- Timestamp:
- 09/07/10 23:05:25 (14 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (2 diffs)
- trunk/phobos/std/traits.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1961 r1964 7 7 8 8 $(WHATSNEW 9 9 $(LI std.algorithm: reduce now works with non-range-based iteration, such as opApply.) 10 10 $(LI std.numeric: Added FFT.) 11 11 $(LI std.process: Added environment, an AA-like interface for environment variables.) 12 12 $(LI std.range: Iota, Stride, Transversal, FrontTransveral now support slicing where possible.) 13 13 $(LI std.range: Added Lockstep, hasLvalueElements.) 14 14 $(LI std.range: Added virtual function-based wrappers (InputRangeObject, OutputRangeObject) for when a binary interface to a range is required.) 15 15 $(LI std.typecons: Added convenience functions for Rebindable.) 16 16 $(L1 std.traits: Added isAssignable, isIterable, ForeachType, isSafe, isUnsafe, EnumMembers.) 17 $(L1 std.traits: hasLocalAliasing, hasLocalObjects and hasLocalRawAliasing are now hasUnsharedAliasing, hasUnsharedObjects and hasUnsharedRawAliasing. Aliases to the old names are included for now for backwards compatibility.) 17 18 $(LI std.typetuple: Added anySatisfy.) 18 19 $(LI $(LINK2 phobos/std_stopwatch.html,std.swopwatch): Added StopWatch, Ticks, systime, apptime, comparingBenchmark, measureTime.) 19 20 ) 20 21 $(BUGSFIXED 21 22 $(LI Unlisted Bug: std.math.pow doesn't work on immutable numbers.) 22 23 $(LI Unlisted Bug: std.math.pow floating point overload expects both arguments to be exact same type.) 23 24 $(LI Unlisted Bug: std.path.join("", "foo") returns "/foo" instead of "foo" on Posix.) 24 25 $(LI Unlisted Bug: std.range.iota() random access primitives inconsistent after popFront on floating point version) 25 26 $(LI Several unlisted bugs in std.range.chain) 26 27 $(LI $(BUGZILLA 2903): Splitter should be bi-dir if the input range is bi-dir.) … … 47 48 $(LI $(BUGZILLA 4404): std.range.Transversal assumes lvalue elements.) 48 49 $(LI $(BUGZILLA 4455): Taking the sqrt of an integer shouldn't require an explicit cast.) 49 50 $(LI $(BUGZILLA 4464): std.range.take does not always return Take!R.) 50 51 $(LI $(BUGZILLA 4518): to!string(enum w/invalid value) produces a somewhat unhelpful error) 51 52 $(LI $(BUGZILLA 4603): array(iota(1, 0)) error.) 52 53 $(LI $(BUGZILLA 4643): Shared values are unwritable.) 53 54 $(LI $(BUGZILLA 4700): to!float("0") fails) 54 55 $(LI $(BUGZILLA 4748): Shadowing declaration error in std.string.tolower) 55 56 $(LI $(BUGZILLA 4789): std.algorithm.sort bug) 56 57 $(LI $(BUGZILLA 4810): dotProduct problem with ints) 58 $(LI $(BUGZILLA 4834): Implicit sharing via delegates in std.concurrency) 57 59 ) 58 60 ) 59 61 60 62 61 63 <div id=version> 62 64 $(UL 63 65 $(NEW 049) 64 66 $(NEW 048) 65 67 $(NEW 047) 66 68 $(NEW 046) trunk/phobos/std/traits.d
r1960 r1964 1075 1075 struct S4 { int a; shared double * b; } 1076 1076 static assert(hasRawLocalAliasing!(S4)); 1077 1077 // struct with an indirect pointer member 1078 1078 struct S5 { S3 a; double b; } 1079 1079 static assert(hasRawLocalAliasing!(S5)); 1080 1080 struct S6 { S4 a; double b; } 1081 1081 static assert(!hasRawLocalAliasing!(S6)); 1082 1082 ---- 1083 1083 */ 1084 1084 1085 private template hasRaw LocalAliasing(T...)1086 { 1087 enum hasRaw LocalAliasing1085 private template hasRawUnsharedAliasing(T...) 1086 { 1087 enum hasRawUnsharedAliasing 1088 1088 = HasRawLocalPointerImpl!(RepresentationTypeTuple!(T)).result; 1089 1089 } 1090 1090 1091 1091 unittest 1092 1092 { 1093 1093 // simple types 1094 static assert(!hasRaw LocalAliasing!(int));1095 static assert(hasRaw LocalAliasing!(char*));1096 static assert(!hasRaw LocalAliasing!(shared char*));1094 static assert(!hasRawUnsharedAliasing!(int)); 1095 static assert(hasRawUnsharedAliasing!(char*)); 1096 static assert(!hasRawUnsharedAliasing!(shared char*)); 1097 1097 // references aren't raw pointers 1098 static assert(!hasRaw LocalAliasing!(Object));1099 static assert(!hasRaw LocalAliasing!(int));1098 static assert(!hasRawUnsharedAliasing!(Object)); 1099 static assert(!hasRawUnsharedAliasing!(int)); 1100 1100 struct S1 { int z; } 1101 static assert(!hasRaw LocalAliasing!(S1));1101 static assert(!hasRawUnsharedAliasing!(S1)); 1102 1102 struct S2 { int* z; } 1103 static assert(hasRaw LocalAliasing!(S2));1103 static assert(hasRawUnsharedAliasing!(S2)); 1104 1104 struct S3 { shared int* z; } 1105 static assert(!hasRaw LocalAliasing!(S3));1105 static assert(!hasRawUnsharedAliasing!(S3)); 1106 1106 struct S4 { int a; int* z; int c; } 1107 static assert(hasRaw LocalAliasing!(S4));1107 static assert(hasRawUnsharedAliasing!(S4)); 1108 1108 struct S5 { int a; shared int* z; int c; } 1109 static assert(!hasRaw LocalAliasing!(S5));1109 static assert(!hasRawUnsharedAliasing!(S5)); 1110 1110 struct S6 { int a; int z; int c; } 1111 static assert(!hasRaw LocalAliasing!(S6));1111 static assert(!hasRawUnsharedAliasing!(S6)); 1112 1112 struct S7 { int a; Object z; int c; } 1113 static assert(!hasRaw LocalAliasing!(S7));1113 static assert(!hasRawUnsharedAliasing!(S7)); 1114 1114 union S8 { int a; int b; } 1115 static assert(!hasRaw LocalAliasing!(S8));1115 static assert(!hasRawUnsharedAliasing!(S8)); 1116 1116 union S9 { int a; int * b; } 1117 static assert(hasRaw LocalAliasing!(S9));1117 static assert(hasRawUnsharedAliasing!(S9)); 1118 1118 union S10 { int a; shared int * b; } 1119 static assert(!hasRaw LocalAliasing!(S10));1119 static assert(!hasRawUnsharedAliasing!(S10)); 1120 1120 typedef int* S11; 1121 static assert(hasRaw LocalAliasing!(S11));1121 static assert(hasRawUnsharedAliasing!(S11)); 1122 1122 typedef shared int* S12; 1123 static assert(hasRaw LocalAliasing!(S12));1123 static assert(hasRawUnsharedAliasing!(S12)); 1124 1124 enum S13 { a }; 1125 static assert(!hasRaw LocalAliasing!(S13));1125 static assert(!hasRawUnsharedAliasing!(S13)); 1126 1126 // indirect members 1127 1127 struct S14 { S9 a; int b; } 1128 static assert(hasRaw LocalAliasing!(S14));1128 static assert(hasRawUnsharedAliasing!(S14)); 1129 1129 struct S15 { S10 a; int b; } 1130 static assert(!hasRaw LocalAliasing!(S15));1130 static assert(!hasRawUnsharedAliasing!(S15)); 1131 1131 struct S16 { S6 a; int b; } 1132 static assert(!hasRaw LocalAliasing!(S16));1133 static assert(hasRaw LocalAliasing!(int[string]));1134 static assert(!hasRaw LocalAliasing!(shared(int[string])));1135 static assert(!hasRaw LocalAliasing!(immutable(int[string])));1132 static assert(!hasRawUnsharedAliasing!(S16)); 1133 static assert(hasRawUnsharedAliasing!(int[string])); 1134 static assert(!hasRawUnsharedAliasing!(shared(int[string]))); 1135 static assert(!hasRawUnsharedAliasing!(immutable(int[string]))); 1136 1136 } 1137 1137 1138 1138 /* 1139 1139 Statically evaluates to $(D true) if and only if $(D T)'s 1140 1140 representation includes at least one non-immutable object reference. 1141 1141 */ 1142 1142 1143 1143 private template hasObjects(T...) 1144 1144 { 1145 1145 static if (T.length == 0) … … 1161 1161 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 private template has LocalObjects(T...)1171 private template hasUnsharedObjects(T...) 1172 1172 { 1173 1173 static if (T.length == 0) 1174 1174 { 1175 enum has LocalObjects = false;1175 enum hasUnsharedObjects = false; 1176 1176 } 1177 1177 else static if (is(T[0] U == typedef)) 1178 1178 { 1179 enum has LocalObjects = hasLocalObjects!(U, T[1 .. $]);1179 enum hasUnsharedObjects = hasUnsharedObjects!(U, T[1 .. $]); 1180 1180 } 1181 1181 else static if (is(T[0] == struct)) 1182 1182 { 1183 enum has LocalObjects = hasLocalObjects!(1183 enum hasUnsharedObjects = hasUnsharedObjects!( 1184 1184 RepresentationTypeTuple!(T[0]), T[1 .. $]); 1185 1185 } 1186 1186 else 1187 1187 { 1188 enum has LocalObjects = (is(T[0] == class) &&1188 enum hasUnsharedObjects = (is(T[0] == class) && 1189 1189 !is(T[0] == immutable) && !is(T[0] == shared)) || 1190 has LocalObjects!(T[1 .. $]);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 1198 immutable;) $(LI a reference to a class type $(D C) and $(D C) is not 1199 immutable.) $(LI an associative array that is not immutable.)) 1199 immutable.) $(LI an associative array that is not immutable.) 1200 $(LI a delegate.)) 1200 1201 */ 1201 1202 1202 1203 template hasAliasing(T...) 1203 1204 { 1204 enum hasAliasing = hasRawAliasing!(T) || hasObjects!(T); 1205 enum hasAliasing = hasRawAliasing!(T) || hasObjects!(T) || 1206 anySatisfy!(isDelegate, T); 1205 1207 } 1206 1208 1207 1209 unittest 1208 1210 { 1209 1211 struct S1 { int a; Object b; } 1210 1212 static assert(hasAliasing!(S1)); 1211 1213 struct S2 { string a; } 1212 1214 static assert(!hasAliasing!(S2)); 1213 1215 struct S3 { int a; immutable Object b; } 1214 1216 static assert(!hasAliasing!(S3)); 1215 1217 struct X { float[3] vals; } 1216 1218 static assert(!hasAliasing!X); 1219 static assert(hasAliasing!(uint[uint])); 1220 static assert(!hasAliasing!(immutable(uint[uint]))); 1221 static assert(hasAliasing!(void delegate())); 1217 1222 } 1218 1223 1219 1224 /** 1220 1225 Returns $(D true) if and only if $(D T)'s representation includes at 1221 1226 least one of the following: $(OL $(LI a raw pointer $(D U*);) $(LI an 1222 1227 array $(D U[]);) $(LI a reference to a class type $(D C).) 1223 $(LI an associative array.) )1228 $(LI an associative array.) $(LI a delegate.)) 1224 1229 */ 1225 1230 1226 1231 template hasIndirections(T) 1227 1232 { 1228 1233 enum hasIndirections = hasIndirectionsImpl!(RepresentationTypeTuple!T); 1229 1234 } 1230 1235 1231 1236 template hasIndirectionsImpl(T...) 1232 1237 { 1233 1238 static if (!T.length) 1234 1239 { 1235 1240 enum hasIndirectionsImpl = false; 1236 1241 } 1237 1242 else 1238 1243 { 1239 1244 enum hasIndirectionsImpl = isPointer!(T[0]) || isDynamicArray!(T[0]) || 1240 1245 is (T[0] : const(Object)) || isAssociativeArray!(T[0]) || 1241 hasIndirectionsImpl!(T[1 .. $]);1246 isDelegate!(T[0]) || hasIndirectionsImpl!(T[1 .. $]); 1242 1247 } 1243 1248 } 1244 1249 1245 1250 unittest 1246 1251 { 1247 1252 struct S1 { int a; Object b; } 1248 1253 static assert(hasIndirections!(S1)); 1249 1254 struct S2 { string a; } 1250 1255 static assert(hasIndirections!(S2)); 1251 1256 struct S3 { int a; immutable Object b; } 1252 1257 static assert(hasIndirections!(S3)); 1253 1258 static assert(hasIndirections!(int[string])); 1254 } 1259 static assert(hasIndirections!(void delegate())); 1260 } 1261 1262 // These are for backwards compatibility, are intentionally lacking ddoc, 1263 // and should eventually be deprecated. 1264 alias hasUnsharedAliasing hasLocalAliasing; 1265 alias hasRawUnsharedAliasing hasRawLocalAliasing; 1266 alias hasUnsharedObjects hasLocalObjects; 1255 1267 1256 1268 /** 1257 1269 Returns $(D true) if and only if $(D T)'s representation includes at 1258 1270 least one of the following: $(OL $(LI a raw pointer $(D U*) and $(D U) 1259 1271 is not immutable or shared;) $(LI an array $(D U[]) and $(D U) is not 1260 1272 immutable or shared;) $(LI a reference to a class type $(D C) and 1261 $(D C) is not immutable or shared.)) 1273 $(D C) is not immutable or shared.) $(LI an associative array that is not 1274 immutable or shared.) $(LI a delegate that is not shared.)) 1262 1275 */ 1263 1276 1264 template hasLocalAliasing(T...) 1265 { 1266 enum hasLocalAliasing = hasRawLocalAliasing!(T) || hasLocalObjects!(T); 1277 template hasUnsharedAliasing(T...) 1278 { 1279 enum hasUnsharedAliasing = hasRawUnsharedAliasing!(T) || 1280 anySatisfy!(unsharedDelegate, T) || hasUnsharedObjects!(T); 1281 } 1282 1283 private template unsharedDelegate(T) 1284 { 1285 enum bool unsharedDelegate = isDelegate!T && !is(T == shared); 1267 1286 } 1268 1287 1269 1288 unittest 1270 1289 { 1271 1290 struct S1 { int a; Object b; } 1272 static assert(has LocalAliasing!(S1));1291 static assert(hasUnsharedAliasing!(S1)); 1273 1292 struct S2 { string a; } 1274 static assert(!has LocalAliasing!(S2));1293 static assert(!hasUnsharedAliasing!(S2)); 1275 1294 struct S3 { int a; immutable Object b; } 1276 static assert(!has LocalAliasing!(S3));1295 static assert(!hasUnsharedAliasing!(S3)); 1277 1296 1278 1297 struct S4 { int a; shared Object b; } 1279 static assert(!has LocalAliasing!(S4));1298 static assert(!hasUnsharedAliasing!(S4)); 1280 1299 struct S5 { char[] a; } 1281 static assert(has LocalAliasing!(S5));1300 static assert(hasUnsharedAliasing!(S5)); 1282 1301 struct S6 { shared char[] b; } 1283 static assert(!has LocalAliasing!(S6));1302 static assert(!hasUnsharedAliasing!(S6)); 1284 1303 struct S7 { float[3] vals; } 1285 static assert(!hasLocalAliasing!(S7)); 1304 static assert(!hasUnsharedAliasing!(S7)); 1305 1306 static assert(hasUnsharedAliasing!(uint[uint])); 1307 static assert(hasUnsharedAliasing!(void delegate())); 1308 static assert(!hasUnsharedAliasing!(shared(void delegate()))); 1286 1309 } 1287 1310 1288 1311 /** 1289 1312 True if $(D S) or any type embedded directly in the representation of $(D S) 1290 1313 defines an elaborate copy constructor. Elaborate copy constructors are 1291 1314 introduced by defining $(D this(this)) for a $(D struct). (Non-struct types 1292 1315 never have elaborate copy constructors.) 1293 1316 */ 1294 1317 template hasElaborateCopyConstructor(S) 1295 1318 { … … 2757 2780 2758 2781 auto dgbar = &bar; 2759 2782 static assert(! isFunctionPointer!(dgbar)); 2760 2783 static assert(! isFunctionPointer!(void delegate())); 2761 2784 static assert(! isFunctionPointer!(foo)); 2762 2785 static assert(! isFunctionPointer!(bar)); 2763 2786 2764 2787 static assert(!isFunctionPointer!((int a) {})); 2765 2788 } 2766 2789 2790 /** 2791 Detect whether $(D T) is a delegate. 2792 */ 2793 template isDelegate(T...) 2794 if(staticLength!T == 1) 2795 { 2796 enum bool isDelegate = is(T[0] == delegate); 2797 } 2798 2799 unittest 2800 { 2801 static assert(isDelegate!(void delegate())); 2802 static assert(isDelegate!(uint delegate(uint))); 2803 static assert(isDelegate!(shared uint delegate(uint))); 2804 static assert(!isDelegate!(uint)); 2805 static assert(!isDelegate!(void function())); 2806 } 2807 2767 2808 2768 2809 /** 2769 2810 Detect whether symbol or type $(D T) is a function, a function pointer or a delegate. 2770 2811 */ 2771 2812 template isSomeFunction(/+@@@BUG4217@@@+/T...) 2772 2813 if (/+@@@BUG4333@@@+/staticLength!(T) == 1) 2773 2814 { 2774 2815 enum bool isSomeFunction = isSomeFunction_bug4333!(T).isSomeFunction; 2775 2816 } 2776 2817 private template isSomeFunction_bug4333(T...)
