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

Changeset 1550

Show
Ignore:
Timestamp:
05/24/10 04:27:06 (15 years ago)
Author:
rsinfu
Message:

Fixed bugzilla 2738: Rebindable should work for interfaces.

Files:

Legend:

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

    r1549 r1550  
    44 
    55 
    66$(VERSION 047, May 9, 2010, =================================================, 
    77 
    88    $(WHATSNEW 
    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 
     14    $(LI $(BUGZILLA 2738): Rebindable should work for interfaces.) 
    1415    $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 
    1516    $(LI $(BUGZILLA 3088): std.xml.check() fails on xml comments) 
    1617    $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 
    1718    $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 
    1819    $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 
    1920    $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 
    2021    $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 
    2122    $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 
    2223    ) 
    2324) 
  • trunk/phobos/std/typecons.d

    r1540 r1550  
    992992a = new Widget; // fine 
    993993---- 
    994994 
    995995You may want to use $(D Rebindable) when you want to have mutable 
    996996storage referring to $(D const) objects, for example an array of 
    997997references that must be sorted in place. $(D Rebindable) does not 
    998998break the soundness of D's type system and does not incur any of the 
    999999risks usually associated with $(D cast). 
    10001000 
    10011001 */ 
    1002 template Rebindable(T) if (is(T : Object) || isArray!(T)) 
     1002template Rebindable(T) if (is(T == class) || is(T == interface) || isArray!(T)) 
    10031003{ 
    10041004    static if (!is(T X == const(U), U) && !is(T X == immutable(U), U)) 
    10051005    { 
    10061006        alias T Rebindable; 
    10071007    } 
    10081008    else static if (isArray!(T)) 
    10091009    { 
    10101010        alias const(ElementType!(T))[] Rebindable; 
    10111011    } 
    10121012    else 
     
    10511051    assert(obj1.get !is null); 
    10521052 
    10531053    Rebindable!(immutable(C)) obj2; 
    10541054    static assert(is(typeof(obj2.get) == immutable(C))); 
    10551055    static assert(is(typeof(obj2.stripped) == C)); 
    10561056    obj2 = new immutable(C); 
    10571057    assert(obj1.get !is null); 
    10581058 
    10591059    // test opDot 
    10601060    assert(obj2.foo == 42); 
     1061 
     1062    interface I { final int foo() const { return 42; } } 
     1063    Rebindable!(I) obj3; 
     1064    static assert(is(typeof(obj3) == I)); 
     1065    static assert(is(typeof(obj3.foo()) == int)); 
    10611066} 
    10621067 
    10631068/** 
    10641069  Order the provided members to minimize size while preserving alignment. 
    10651070  Returns a declaration to be mixed in. 
    10661071 
    10671072Example: 
    10681073--- 
    10691074struct Banner { 
    10701075  mixin(alignForSize!(byte[6], double)(["name", "height"]));