Changeset 1554
- Timestamp:
- 05/26/10 05:59:01 (15 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/typecons.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1552 r1554 9 9 $(LI std.functional: toDelegate now accepts callable(function pointers, delegates and objects implement opCall) ) 10 10 $(LI std.traits: Added templates to get compile-time information about functions.) 11 11 $(LI std.typecons: Added tie and AutoImplement.) 12 12 ) 13 13 $(BUGSFIXED 14 14 $(LI $(BUGZILLA 2738): Rebindable should work for interfaces.) 15 15 $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 16 16 $(LI $(BUGZILLA 3088): std.xml.check() fails on xml comments) 17 17 $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 18 18 $(LI $(BUGZILLA 3465): isIdeographic can be wrong in std.xml) 19 $(LI $(BUGZILLA 3653): Problem sorting array of Rebindable) 19 20 $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 20 21 $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 21 22 $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 22 23 $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 23 24 $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 24 25 $(LI $(BUGZILLA 4219): hasAliasing does not care about immutable) 25 26 ) 26 27 ) 27 28 28 29 <div id=version> trunk/phobos/std/typecons.d
r1550 r1554 1015 1015 { 1016 1016 private union 1017 1017 { 1018 1018 T original; 1019 1019 U stripped; 1020 1020 } 1021 1021 void opAssign(T another) 1022 1022 { 1023 1023 stripped = cast(U) another; 1024 1024 } 1025 void opAssign(Rebindable another) 1026 { 1027 stripped = another.stripped; 1028 } 1029 static if (is(T == const U)) 1030 { 1031 // safely assign immutable to const 1032 void opAssign(Rebindable!(immutable U) another) 1033 { 1034 stripped = another.stripped; 1035 } 1036 } 1025 1037 static Rebindable opCall(T initializer) 1026 1038 { 1027 1039 Rebindable result; 1028 1040 result = initializer; 1029 1041 return result; 1030 1042 } 1031 1043 alias original get; 1032 1044 T opDot() { 1033 1045 return original; 1034 1046 } … … 1055 1067 static assert(is(typeof(obj2.stripped) == C)); 1056 1068 obj2 = new immutable(C); 1057 1069 assert(obj1.get !is null); 1058 1070 1059 1071 // test opDot 1060 1072 assert(obj2.foo == 42); 1061 1073 1062 1074 interface I { final int foo() const { return 42; } } 1063 1075 Rebindable!(I) obj3; 1064 1076 static assert(is(typeof(obj3) == I)); 1065 static assert(is(typeof(obj3.foo()) == int)); 1077 1078 Rebindable!(const I) obj4; 1079 static assert(is(typeof(obj4.get) == const I)); 1080 static assert(is(typeof(obj4.stripped) == I)); 1081 static assert(is(typeof(obj4.foo()) == int)); 1082 obj4 = new class I {}; 1083 1084 Rebindable!(immutable C) obj5i; 1085 Rebindable!(const C) obj5c; 1086 obj5c = obj5c; 1087 obj5c = obj5i; 1088 obj5i = obj5i; 1089 static assert(!__traits(compiles, obj5i = obj5c)); 1066 1090 } 1067 1091 1068 1092 /** 1069 1093 Order the provided members to minimize size while preserving alignment. 1070 1094 Returns a declaration to be mixed in. 1071 1095 1072 1096 Example: 1073 1097 --- 1074 1098 struct Banner { 1075 1099 mixin(alignForSize!(byte[6], double)(["name", "height"]));
