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

Changeset 1715

Show
Ignore:
Timestamp:
07/04/10 21:13:07 (14 years ago)
Author:
andrei
Message:

Temporary workaround for bug 4426

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/array.d

    r1713 r1715  
    374374Implements the range interface primitive $(D back) for built-in 
    375375arrays. Due to the fact that nonmember functions can be called with 
    376376the first argument using the dot notation, $(D array.back) is 
    377377equivalent to $(D back(array)). 
    378378 
    379379Example: 
    380380---- 
    381381void main() 
    382382{ 
    383383    int[] a = [ 1, 2, 3 ]; 
    384     assert(a.front == 1); 
     384    assert(a.back == 3); 
    385385} 
    386386---- 
    387387*/ 
    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"); 
     388ref typeof(A.init[0]) back(A)(A a) 
     389if (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    } 
    392401    return a[$ - 1]; 
     402} 
     403 
     404unittest 
     405{ 
     406    int[] a = [ 1, 2, 3 ]; 
     407    assert(a.back == 3); 
     408    a.back += 4; 
     409    assert(a.back == 7); 
    393410} 
    394411 
    395412dchar back(A)(A a) 
    396413if (is(typeof(A.init[0])) && isNarrowString!A && a[0].sizeof < 4) 
    397414{ 
    398415    assert(a.length, "Attempting to fetch the back of an empty array"); 
    399416    auto n = a.length; 
    400417    const p = a.ptr + n; 
    401418    if (n >= 1 && (p[-1] & 0b1100_0000) != 0b1000_0000) 
    402419    {