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

Changeset 1554

Show
Ignore:
Timestamp:
05/26/10 05:59:01 (15 years ago)
Author:
rsinfu
Message:

Fixed bugzilla 3653: Problem sorting array of Rebindable.
Thanks to pc for the patch!

std.algorithm.sort does assignments over input array, but Rebindable did not have opAssign overload for Rebindable itself. This change implements Rebindable.opAssign(Rebindable).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r1552 r1554  
    99    $(LI std.functional: toDelegate now accepts callable(function pointers, delegates and objects implement opCall) ) 
    1010    $(LI std.traits: Added templates to get compile-time information about functions.) 
    1111    $(LI std.typecons: Added tie and AutoImplement.) 
    1212    ) 
    1313    $(BUGSFIXED 
    1414    $(LI $(BUGZILLA 2738): Rebindable should work for interfaces.) 
    1515    $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 
    1616    $(LI $(BUGZILLA 3088): std.xml.check() fails on xml comments) 
    1717    $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 
    1818    $(LI $(BUGZILLA 3465): isIdeographic can be wrong in std.xml) 
     19    $(LI $(BUGZILLA 3653): Problem sorting array of Rebindable) 
    1920    $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 
    2021    $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 
    2122    $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 
    2223    $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 
    2324    $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 
    2425    $(LI $(BUGZILLA 4219): hasAliasing does not care about immutable) 
    2526    ) 
    2627) 
    2728 
    2829<div id=version> 
  • trunk/phobos/std/typecons.d

    r1550 r1554  
    10151015        { 
    10161016            private union 
    10171017            { 
    10181018                T original; 
    10191019                U stripped; 
    10201020            } 
    10211021            void opAssign(T another) 
    10221022            { 
    10231023                stripped = cast(U) another; 
    10241024            } 
     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            } 
    10251037            static Rebindable opCall(T initializer) 
    10261038            { 
    10271039                Rebindable result; 
    10281040                result = initializer; 
    10291041                return result; 
    10301042            } 
    10311043            alias original get; 
    10321044            T opDot() { 
    10331045                return original; 
    10341046            } 
     
    10551067    static assert(is(typeof(obj2.stripped) == C)); 
    10561068    obj2 = new immutable(C); 
    10571069    assert(obj1.get !is null); 
    10581070 
    10591071    // test opDot 
    10601072    assert(obj2.foo == 42); 
    10611073 
    10621074    interface I { final int foo() const { return 42; } } 
    10631075    Rebindable!(I) obj3; 
    10641076    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)); 
    10661090} 
    10671091 
    10681092/** 
    10691093  Order the provided members to minimize size while preserving alignment. 
    10701094  Returns a declaration to be mixed in. 
    10711095 
    10721096Example: 
    10731097--- 
    10741098struct Banner { 
    10751099  mixin(alignForSize!(byte[6], double)(["name", "height"]));