Changeset 1547
- Timestamp:
- 05/23/10 18:09:19 (15 years ago)
- Files:
-
- trunk/docsrc/changelog.dd (modified) (1 diff)
- trunk/phobos/std/array.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/changelog.dd
r1546 r1547 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 2835): std.socket.TcpSocket doesn't actually connect) 15 15 $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 16 16 $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 17 17 $(LI $(BUGZILLA 3880): std.regex functions with const/immutable Regex object) 18 18 $(LI $(BUGZILLA 4109): writeln doesn't work with empty static array) 19 19 $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 20 $(LI $(BUGZILLA 4228): std.array.replace contains 2 bugs) 20 21 ) 21 22 ) 22 23 23 24 <div id=version> 24 25 $(UL 25 26 $(NEW 047) 26 27 $(NEW 046) 27 28 $(NEW 045) 28 29 $(NEW 044) 29 30 $(NEW 043) trunk/phobos/std/array.d
r1501 r1547 549 549 // int[] a = [1, 2, 3, 4, 5]; 550 550 // erase(a, 2u); 551 551 // assert(a == [1, 2, 4, 5]); 552 552 // } 553 553 554 554 /** 555 555 Replaces elements from $(D array) with indices ranging from $(D from) 556 556 (inclusive) to $(D to) (exclusive) with the range $(D stuff). Expands 557 557 or shrinks the array as needed. 558 558 */ 559 void replace(T, Range)(ref T[] array, size_t from, size_t to, 560 Range stuff)559 void replace(T, Range)(ref T[] array, size_t from, size_t to, Range stuff) 560 if (is(ElementType!Range == T)) 561 561 { 562 562 // container = container[0 .. from] ~ stuff ~ container[to .. $]; 563 563 if (overlap(array, stuff)) 564 564 { 565 565 // use slower/conservative method 566 566 array = array[0 .. from] ~ stuff ~ array[to .. $]; 567 567 } 568 568 else if (stuff.length <= to - from) 569 569 { 570 570 // replacement reduces length 571 571 // BUG 2128 572 572 //immutable stuffEnd = from + stuff.length; 573 573 auto stuffEnd = from + stuff.length; 574 574 array[from .. stuffEnd] = stuff; 575 remove(array, tuple(stuffEnd, to));575 array = remove(array, tuple(stuffEnd, to)); 576 576 } 577 577 else 578 578 { 579 579 // replacement increases length 580 580 // @@@TODO@@@: optimize this 581 581 immutable replaceLen = to - from; 582 582 array[from .. to] = stuff[0 .. replaceLen]; 583 583 insert(array, to, stuff[replaceLen .. $]); 584 584 } 585 585 } 586 586 587 588 void replace(T, Range)(ref T[] array, size_t from, size_t to, Range stuff) 589 if (!is(ElementType!Range == T) && is(Unqual!Range == void*)) 590 { 591 replace(array, from, to, cast(T[])[]); 592 } 593 594 595 587 596 unittest 588 597 { 589 598 int[] a = [1, 4, 5]; 590 599 replace(a, 1u, 2u, [2, 3, 4]); 591 600 assert(a == [1, 2, 3, 4, 5]); 601 replace(a, 1u, 2u, cast(int[])[]); 602 assert(a == [1, 3, 4, 5]); 603 replace(a, 1u, 2u, null); 604 assert(a == [1, 4, 5]); 592 605 } 593 606 594 607 /** 595 608 Implements an output range that appends data to an array. This is 596 609 recommended over $(D a ~= data) because it is more efficient. 597 610 598 611 Example: 599 612 ---- 600 613 string arr; 601 614 auto app = appender(&arr);
