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

Changeset 1688

Show
Ignore:
Timestamp:
06/23/10 12:45:32 (14 years ago)
Author:
dsimcha
Message:

save() for std.algorithm.filter, WITH proper unittests.

Files:

Legend:

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

    r1685 r1688  
    22 
    33$(D_S D Change Log, 
    44 
    55 
    66$(VERSION 048, Jun 11, 2010, =================================================, 
    77 
    88    $(WHATSNEW 
    99    $(LI std.string: icmp() now works with all built-in string types.) 
    1010    ) 
    1111    $(BUGSFIXED 
     12    $(L1 $(Unlisted Bug):  std.algorithm.filter not a forward range. 
    1213    $(LI $(BUGZILLA 978): std.utf's toUTF* functions accept some invalid and reject some valid UTF) 
    1314    $(LI $(BUGZILLA 996): Error in doc on implicit conversion between pointer and array) 
    1415    $(LI $(BUGZILLA 2275): std.utf.toUTF16z() should return const(wchar)*) 
    1516    $(LI $(BUGZILLA 2872): Length, opIndex for Map) 
    1617    $(LI $(BUGZILLA 3202): std.math.pow cause dead loop) 
    1718    $(LI $(BUGZILLA 3355): std.string.cmp works incorrectly for mixed-type and different-length strings) 
    1819    $(LI $(BUGZILLA 3386): to!bool(string) is not implemented) 
    1920    $(LI $(BUGZILLA 3436): std.functional.compose with only one function) 
    2021    $(LI $(BUGZILLA 3439): std.range.Sequence.opIndex not consistent after calling popFront().) 
    2122    $(LI $(BUGZILLA 3447): std.file uses unconventional file permissions) 
    2223    $(LI $(BUGZILLA 3961): Error with to!(somestruct)) 
    2324    $(LI $(BUGZILLA 4109): (reopened) writeln doesn't work with empty static array) 
    2425    $(LI $(BUGZILLA 4171): std.random.uniform does not work for a range of characters) 
    2526    $(LI $(BUGZILLA 4327): std.container.Array.Range.~this() tries to call free(T[])) 
     27    $(LI $(BUGZILLA 4362): std.range.repeat and cycle do not have a .save() method 
    2628    $(LI $(BUGZILLA 4363): std.algorithm.Until is not a forward range) 
    2729    ) 
    2830) 
    2931 
    3032<div id=version> 
    3133$(UL 
    3234    $(NEW 048) 
    3335    $(NEW 047) 
    3436    $(NEW 046) 
    3537    $(NEW 045) 
  • trunk/phobos/std/algorithm.d

    r1682 r1688  
    574574    { 
    575575        do 
    576576        { 
    577577            _input.popFront; 
    578578        } while (!_input.empty && !pred(_input.front)); 
    579579    } 
    580580 
    581581    ElementType!(Range) front() 
    582582    { 
    583583        return _input.front; 
     584    } 
     585 
     586    static if(isForwardRange!Range) 
     587    { 
     588        @property typeof(this) save() 
     589        { 
     590            return typeof(this)(_input.save); 
     591        } 
    584592    } 
    585593} 
    586594 
    587595unittest 
    588596{ 
    589597    int[] a = [ 3, 4 ]; 
    590598    auto r = filter!("a > 3")(a); 
    591599    assert(equal(r, [ 4 ][])); 
     600    static assert(isForwardRange!(typeof(r))); 
    592601 
    593602    a = [ 1, 22, 3, 42, 5 ]; 
    594603    auto under10 = filter!("a < 10")(a); 
    595604    assert(equal(under10, [1, 3, 5][])); 
    596      
     605    static assert(isForwardRange!(typeof(under10))); 
     606 
    597607    auto infinite = filter!"a > 2"(repeat(3)); 
    598608    static assert(isInfinite!(typeof(infinite))); 
     609    static assert(isForwardRange!(typeof(infinite))); 
    599610} 
    600611 
    601612// move 
    602613/** 
    603614Moves $(D source) into $(D target) via a destructive 
    604615copy. Specifically: $(UL $(LI If $(D hasAliasing!T) is true (see 
    605616$(XREF traits, hasAliasing)), then the representation of $(D source) 
    606617is bitwise copied into $(D target) and then $(D source = T.init) is 
    607618evaluated.)  $(LI Otherwise, $(D target = source) is evaluated.)) See 
    608619also $(XREF contracts, pointsTo).