Changeset 1739
- Timestamp:
- 07/09/10 03:50:31 (14 years ago)
- Files:
-
- trunk/phobos/std/array.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/array.d
r1733 r1739 58 58 } 59 59 r.popFront; 60 60 } 61 61 return result; 62 62 } 63 63 else 64 64 { 65 65 auto a = appender!(E[])(); 66 66 foreach (e; r) 67 67 { 68 a.put(e);68 put(a, e); 69 69 } 70 70 return a.data; 71 71 } 72 72 // // 2. Initialize the memory 73 73 // size_t constructedElements = 0; 74 74 // scope(failure) 75 75 // { 76 76 // // Deconstruct only what was constructed 77 77 // foreach_reverse (i; 0 .. constructedElements) 78 78 // { … … 435 435 n -= 4; 436 436 return decode(a, n); 437 437 } 438 438 else 439 439 { 440 440 throw new UtfException("Invalid UTF character at end of string"); 441 441 } 442 442 } 443 443 444 444 445 /* *445 /* 446 446 Implements the range interface primitive $(D put) for built-in 447 447 arrays. Due to the fact that nonmember functions can be called with 448 448 the first argument using the dot notation, $(D array.put(e)) is 449 449 equivalent to $(D put(array, e)). 450 450 451 451 Example: 452 452 ---- 453 453 void main() 454 454 { 455 455 int[] a = [ 1, 2, 3 ]; 456 456 int[] b = a; 457 457 a.put(5); 458 458 assert(a == [ 2, 3 ]); 459 459 assert(b == [ 5, 2, 3 ]); 460 460 } 461 461 ---- 462 462 */ 463 void put(T, E)(ref T[] a, E e) { assert(a.length); a[0] = e; a = a[1 .. $]; } 463 alias std.range.put put; 464 //void put(T, E)(ref T[] a, E e) { assert(a.length); a[0] = e; a = a[1 .. $]; } 464 465 465 466 // overlap 466 467 /* 467 468 Returns the overlapping portion, if any, of two arrays. Unlike $(D 468 469 equal), $(D overlap) only compares the pointers in the ranges, not the 469 470 values referred by them. If $(D r1) and $(D r2) have an overlapping 470 471 slice, returns that slice. Otherwise, returns the null slice. 471 472 472 473 Example: 473 474 ----
