Changeset 1702
- Timestamp:
- 07/01/10 02:24:58 (14 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/algorithm.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1698 r1702 16 16 $(LI $(BUGZILLA 978): std.utf's toUTF* functions accept some invalid and reject some valid UTF) 17 17 $(LI $(BUGZILLA 996): Error in doc on implicit conversion between pointer and array) 18 18 $(LI $(BUGZILLA 2275): std.utf.toUTF16z() should return const(wchar)*) 19 19 $(LI $(BUGZILLA 2872): Length, opIndex for Map) 20 20 $(LI $(BUGZILLA 3202): std.math.pow cause dead loop) 21 21 $(LI $(BUGZILLA 3355): std.string.cmp works incorrectly for mixed-type and different-length strings) 22 22 $(LI $(BUGZILLA 3386): to!bool(string) is not implemented) 23 23 $(LI $(BUGZILLA 3436): std.functional.compose with only one function) 24 24 $(LI $(BUGZILLA 3439): std.range.Sequence.opIndex not consistent after calling popFront().) 25 25 $(LI $(BUGZILLA 3447): std.file uses unconventional file permissions) 26 $(LI $(BUGZILLA 3872): std.algorithm.filter could become bidirectional if its input range is bidir) 26 27 $(LI $(BUGZILLA 3874): std.range.stride assumes a bidirectional input range) 27 28 $(LI $(BUGZILLA 3937): os.path.dirname fails on absolute path) 28 29 $(LI $(BUGZILLA 3961): Error with to!(somestruct)) 29 30 $(LI $(BUGZILLA 4109): (reopened) writeln doesn't work with empty static array) 30 31 $(LI $(BUGZILLA 4171): std.random.uniform does not work for a range of characters) 31 32 $(LI $(BUGZILLA 4260): windows & basename) 32 33 $(LI $(BUGZILLA 4305): Take, Chain on top of ranges w/o moveFront() ) 33 34 $(LI $(BUGZILLA 4327): std.container.Array.Range.~this() tries to call free(T[])) 34 35 $(LI $(BUGZILLA 4362): std.range.repeat and cycle do not have a .save() method) 35 36 $(LI $(BUGZILLA 4363): std.algorithm.Until is not a forward range) trunk/phobos/std/algorithm.d
r1698 r1702 558 558 } 559 559 560 560 struct Filter(alias pred, Range) if (isInputRange!(Range)) 561 561 { 562 562 Range _input; 563 563 564 564 this(Range r) 565 565 { 566 566 _input = r; 567 567 while (!_input.empty && !pred(_input.front)) _input.popFront; 568 static if (isBidirectionalRange!Range) { 569 while (!_input.empty && !pred(_input.back)) _input.popBack; 570 } 571 568 572 } 569 573 570 574 ref Filter opSlice() 571 575 { 572 576 return this; 573 577 } 574 578 575 579 static if(isInfinite!Range) { 576 580 enum bool empty = false; 577 581 } else { … … 584 588 { 585 589 _input.popFront; 586 590 } while (!_input.empty && !pred(_input.front)); 587 591 } 588 592 589 593 ElementType!(Range) front() 590 594 { 591 595 return _input.front; 592 596 } 593 597 598 static if (isBidirectionalRange!Range) { 599 void popBack() 600 { 601 do 602 { 603 _input.popBack; 604 } while (!_input.empty && !pred(_input.back)); 605 } 606 607 ElementType!(Range) back() { return _input.back;} 608 } 609 610 594 611 static if(isForwardRange!Range) 595 612 { 596 613 @property typeof(this) save() 597 614 { 598 615 return typeof(this)(_input.save); 599 616 } 600 617 } 601 618 } 602 619 603 620 unittest … … 609 626 610 627 a = [ 1, 22, 3, 42, 5 ]; 611 628 auto under10 = filter!("a < 10")(a); 612 629 assert(equal(under10, [1, 3, 5][])); 613 630 static assert(isForwardRange!(typeof(under10))); 614 631 615 632 auto infinite = filter!"a > 2"(repeat(3)); 616 633 static assert(isInfinite!(typeof(infinite))); 617 634 static assert(isForwardRange!(typeof(infinite))); 618 635 636 auto nums = [0,1,2,3,4]; 637 auto forward = filter!"a % 2 == 0"(nums); 638 assert(equal(retro(forward), [4,2,0][])); // f is a bidirectional range 639 640 619 641 foreach(DummyType; AllDummyRanges) { 620 642 DummyType d; 621 643 auto f = filter!"a & 1"(d); 622 644 assert(equal(f, [1,3,5,7,9])); 645 646 static if(isForwardRange!DummyType) { 647 static assert(isForwardRange!(typeof(f))); 648 } 649 650 static if(isBidirectionalRange!DummyType) { 651 static assert(isBidirectionalRange!(typeof(f))); 652 assert(equal(retro(f), [9,7,5,3,1])); 653 } 623 654 } 624 655 } 625 656 626 657 // move 627 658 /** 628 659 Moves $(D source) into $(D target) via a destructive 629 660 copy. Specifically: $(UL $(LI If $(D hasAliasing!T) is true (see 630 661 $(XREF traits, hasAliasing)), then the representation of $(D source) 631 662 is bitwise copied into $(D target) and then $(D source = T.init) is 632 663 evaluated.) $(LI Otherwise, $(D target = source) is evaluated.)) See
