Changeset 1715
- Timestamp:
- 07/04/10 21:13:07 (14 years ago)
- Files:
-
- trunk/phobos/std/array.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/array.d
r1713 r1715 374 374 Implements the range interface primitive $(D back) for built-in 375 375 arrays. Due to the fact that nonmember functions can be called with 376 376 the first argument using the dot notation, $(D array.back) is 377 377 equivalent to $(D back(array)). 378 378 379 379 Example: 380 380 ---- 381 381 void main() 382 382 { 383 383 int[] a = [ 1, 2, 3 ]; 384 assert(a. front == 1);384 assert(a.back == 3); 385 385 } 386 386 ---- 387 387 */ 388 ref typeof(A.init[0]) back(A)(A a) if (is(typeof(A.init[0])) 389 && !isNarrowString!A) 390 { 391 assert(a.length, "Attempting to fetch the back of an empty array"); 388 ref typeof(A.init[0]) back(A)(A a) 389 if (is(typeof(A.init[0])) && !isNarrowString!A) 390 { 391 // @@@BUG@@@ The assert below crashes the unittest due to a bug in 392 // the compiler 393 version (bug4426) 394 { 395 assert(a.length, "Attempting to fetch the back of an empty array"); 396 } 397 else 398 { 399 assert(a.length); 400 } 392 401 return a[$ - 1]; 402 } 403 404 unittest 405 { 406 int[] a = [ 1, 2, 3 ]; 407 assert(a.back == 3); 408 a.back += 4; 409 assert(a.back == 7); 393 410 } 394 411 395 412 dchar back(A)(A a) 396 413 if (is(typeof(A.init[0])) && isNarrowString!A && a[0].sizeof < 4) 397 414 { 398 415 assert(a.length, "Attempting to fetch the back of an empty array"); 399 416 auto n = a.length; 400 417 const p = a.ptr + n; 401 418 if (n >= 1 && (p[-1] & 0b1100_0000) != 0b1000_0000) 402 419 {
