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

Changeset 2032

Show
Ignore:
Timestamp:
09/18/10 21:00:52 (14 years ago)
Author:
dsimcha
Message:

Bug 4888: Heavy reliance on Bug 3534 in Phobos range usage. I used a different approach here than the first one I tried. I only did what was necessary to make Phobos work instead of trying to fix the deeper issue of making std.algorithm to work w/ const/immutable arrays.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r2031 r2032  
    11Ddoc 
    22 
    33$(D_S D Change Log, 
    44 
    55$(VERSION 050, Mmm dd 2010, =================================================, 
    66 
    77 
    88    $(WHATSNEW 
    99    $(LI std.traits:  Most higher-order ranges now work with const/immutable arrays and other ranges  
    1010    with a natural tail const, and ranges w/ const/immutable elements.) 
     11    $(LI Bug 4888:  Heavy reliance on Bug 3534 in Phobos range usage) 
    1112    $(LI std.typecons:  Several improvements to the Tuple struct template: 
    1213        $(UL $(LI  Tuple members are now accessible with the syntax a[0], a[1] etc.) 
    1314             $(LI  Eliminated an internal union. See $(BUGZILLA 4421) and $(BUGZILLA 4846).) 
    1415             $(LI  Worked around $(BUGZILLA 4424). Got opAssign back.) 
    1516             $(LI  Made Tuple.slice!(from, to) to preserve field names if any.) 
    1617             $(LI  Added isTuple!(T) template.) 
    1718        )) 
    1819    ) 
    1920    $(BUGSFIXED 
    2021    $(LI Unlisted bug:  std.exception.pointsTo() calls postblit on subobjects.) 
  • trunk/phobos/std/algorithm.d

    r2009 r2032  
    104104        { 
    105105            return Map!(adjoin!(staticMap!(unaryFun, fun)), Range)(r); 
    106106        } 
    107107        else 
    108108        { 
    109109            return Map!(unaryFun!fun, Range)(r); 
    110110        } 
    111111    } 
    112112} 
    113113 
    114 struct Map(alias fun, Range) if (isInputRange!(Range)) 
    115 
     114struct Map(alias fun, Range) if (isInputRange!(Unqual!Range)) 
     115
     116    alias Unqual!Range R; 
    116117    alias fun _fun; 
    117     alias typeof({ return _fun(.ElementType!(Range).init); }()) ElementType; 
    118     Unqual!Range _input; 
     118    alias typeof({ return _fun(.ElementType!(R).init); }()) ElementType; 
     119    R _input; 
    119120    Unqual!ElementType _cache; 
    120121 
    121     static if (isBidirectionalRange!(Range)) 
     122    static if (isBidirectionalRange!(R)) 
    122123    { 
    123124    // Using a second cache would lead to at least 1 extra function evaluation 
    124125    // and wasted space when 99% of the time this range will only be iterated 
    125126    // over in the forward direction.  Use a bool to determine whether cache 
    126127    // is front or back instead. 
    127128        bool cacheIsBack_; 
    128129 
    129130        private void fillCacheBack() 
    130131        { 
    131132            if (!_input.empty) _cache = _fun(_input.back); 
     
    145146        { 
    146147            _input.popBack; 
    147148            fillCacheBack(); 
    148149        } 
    149150    } 
    150151 
    151152    private void fillCache() 
    152153    { 
    153154        if (!_input.empty) _cache = _fun(_input.front); 
    154155 
    155         static if(isBidirectionalRange!(Range)) 
     156        static if(isBidirectionalRange!(R)) 
    156157        { 
    157158            cacheIsBack_ = false; 
    158159        } 
    159160    } 
    160161 
    161     this(Range input) 
     162    this(R input) 
    162163    { 
    163164        _input = input; 
    164165        fillCache; 
    165166    } 
    166167 
    167         static if (isInfinite!Range
    168     { 
    169                 // Propagate infinite-ness. 
    170                 enum bool empty = false; 
    171        
     168    static if (isInfinite!R
     169    { 
     170        // Propagate infinite-ness. 
     171        enum bool empty = false; 
     172   
    172173    else 
    173174    { 
    174175                @property bool empty() 
    175176        { 
    176177                        return _input.empty; 
    177178                } 
    178179        } 
    179180 
    180181    void popFront() 
    181182    { 
    182183        _input.popFront; 
    183184        fillCache(); 
    184185    } 
    185186 
    186187    @property ElementType front() 
    187188    { 
    188         static if (isBidirectionalRange!(Range)) 
     189        static if (isBidirectionalRange!(R)) 
    189190        { 
    190191            if (cacheIsBack_) 
    191192            { 
    192193                fillCache(); 
    193194            } 
    194195        } 
    195196        return _cache; 
    196197    } 
    197198 
    198     static if (isRandomAccessRange!Range
     199    static if (isRandomAccessRange!R
    199200    { 
    200201        ElementType opIndex(size_t index) 
    201202        { 
    202203            return _fun(_input[index]); 
    203204        } 
    204205    } 
    205206 
    206207    // hasLength is busted, Bug 2873 
    207208    static if (is(typeof(_input.length) : size_t) 
    208209        || is(typeof(_input.length()) : size_t)) 
    209210    { 
    210211        @property size_t length() 
    211212        { 
    212213            return _input.length; 
    213214        } 
    214215    } 
    215216 
    216     static if (hasSlicing!(Range)) 
     217    static if (hasSlicing!(R)) 
    217218    { 
    218219        typeof(this) opSlice(size_t lowerBound, size_t upperBound) 
    219220        { 
    220221            return typeof(this)(_input[lowerBound..upperBound]); 
    221222        } 
    222223    } 
    223224 
    224         static if (isForwardRange!Range
    225         @property Map save() 
    226        
    227             auto result = this; 
    228             result._input = result._input.save; 
    229             return result; 
    230        
     225    static if (isForwardRange!R
     226    @property Map save() 
     227   
     228        auto result = this; 
     229        result._input = result._input.save; 
     230        return result; 
     231   
    231232} 
    232233 
    233234unittest 
    234235{ 
    235236    debug(std_algorithm) scope(success) 
    236237        writeln("unittest @", __FILE__, ":", __LINE__, " done."); 
    237238    alias map!(to!string) stringize; 
    238239    assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ])); 
    239240    uint counter; 
    240241    alias map!((a) { return counter++; }) count; 
     
    843844version (all) 
    844845{ 
    845846/* This is the older version. Too many problems with the newer one. 
    846847 */ 
    847848Filter!(unaryFun!(pred), Range) 
    848849filter(alias pred, Range)(Range rs) 
    849850{ 
    850851    return typeof(return)(rs); 
    851852} 
    852853 
    853 struct Filter(alias pred, Range) if (isInputRange!(Range)) 
    854 
    855     Unqual!Range _input; 
    856  
    857     this(Range r) 
     854struct Filter(alias pred, Range) if (isInputRange!(Unqual!Range)) 
     855
     856    alias Unqual!Range R; 
     857    R _input; 
     858 
     859    this(R r) 
    858860    { 
    859861        _input = r; 
    860862        while (!_input.empty && !pred(_input.front)) _input.popFront; 
    861863    } 
    862864 
    863865    ref Filter opSlice() 
    864866    { 
    865867        return this; 
    866868    } 
    867869 
     
    872874        { 
    873875            _input.popFront; 
    874876        } while (!_input.empty && !pred(_input.front)); 
    875877    } 
    876878 
    877879    ElementType!(Range) front() 
    878880    { 
    879881        return _input.front; 
    880882    } 
    881883 
    882     static if(isForwardRange!Range
     884    static if(isForwardRange!R
    883885    { 
    884886        @property typeof(this) save() 
    885887        { 
    886888            return typeof(this)(_input); 
    887889        } 
    888890    } 
    889891} 
    890892 
    891893unittest 
    892894{ 
  • trunk/phobos/std/array.d

    r2005 r2032  
    246246    assert(b is a); 
    247247} 
    248248---- 
    249249 */ 
    250250 
    251251@property T[] save(T)(T[] a) 
    252252{ 
    253253    return a; 
    254254} 
    255255 
     256private template notConst(T) { 
     257    enum notConst = !is(T == const) && !is(T == immutable); 
     258} 
     259 
    256260/** 
    257261Implements the range interface primitive $(D popFront) for built-in 
    258262arrays. Due to the fact that nonmember functions can be called with 
    259263the first argument using the dot notation, $(D array.popFront) is 
    260264equivalent to $(D popFront(array)). 
    261265 
    262266 
    263267Example: 
    264268---- 
    265269void main() 
    266270{ 
    267271    int[] a = [ 1, 2, 3 ]; 
    268272    a.popFront; 
    269273    assert(a == [ 2, 3 ]); 
    270274} 
    271275---- 
    272276*/ 
    273277 
    274 void popFront(T)(ref T[] a) if (!is(Unqual!T == char) && !is(Unqual!T == wchar)) 
    275 
     278void popFront(A)(ref A a) 
     279if(!isNarrowString!A && isDynamicArray!A && notConst!A) 
     280
     281    alias typeof(A[0]) T; 
    276282    assert(a.length, "Attempting to popFront() past the end of an array of " 
    277283            ~ T.stringof); 
    278284    a = a[1 .. $]; 
    279285} 
    280286 
    281287unittest 
    282288{ 
    283289    //@@@BUG 2608@@@ 
    284290    //auto a = [ 1, 2, 3 ]; 
    285291    int[] a = [ 1, 2, 3 ]; 
    286292    a.popFront; 
    287293    assert(a == [ 2, 3 ]); 
    288 
    289  
    290 void popFront(T)(ref T[] a) if (is(Unqual!T == char) || is(Unqual!T == wchar)) 
    291 
     294 
     295    static assert(!__traits(compiles, popFront!(immutable int[]))); 
     296
     297 
     298void popFront(A)(ref A a) 
     299if(isNarrowString!A && notConst!A) 
     300
     301    alias typeof(a[0]) T; 
    292302    assert(a.length, "Attempting to popFront() past the end of an array of " 
    293303            ~ T.stringof); 
    294304    a = a[std.utf.stride(a, 0) .. $]; 
    295305} 
    296306 
    297307unittest 
    298308{ 
    299309    string s1 = "\xC2\xA9hello"; 
    300310    s1.popFront(); 
    301311    assert(s1 == "hello"); 
    302312    wstring s2 = "\xC2\xA9hello"; 
    303313    s2.popFront(); 
    304314    assert(s2 == "hello"); 
    305315    string s3 = "\u20AC100"; 
    306316    //write(s3, '\n'); 
     317 
     318    static assert(!__traits(compiles, popFront!(immutable string))); 
    307319} 
    308320 
    309321/** 
    310322Implements the range interface primitive $(D popBack) for built-in 
    311323arrays. Due to the fact that nonmember functions can be called with 
    312324the first argument using the dot notation, $(D array.popBack) is 
    313325equivalent to $(D popBack(array)). 
    314326 
    315327 
    316328Example: 
    317329---- 
    318330void main() 
    319331{ 
    320332    int[] a = [ 1, 2, 3 ]; 
    321333    a.popBack; 
    322334    assert(a == [ 1, 2 ]); 
    323335} 
    324336---- 
    325337*/ 
    326338 
    327 void popBack(T)(ref T[] a) if (!is(Unqual!T == char) && !is(Unqual!T == wchar)) 
     339void popBack(A)(ref A a) 
     340if(isDynamicArray!A && !isNarrowString!A && notConst!A) 
    328341{ 
    329342    assert(a.length); 
    330343    a = a[0 .. $ - 1]; 
    331344} 
    332345 
    333346unittest 
    334347{ 
    335348    //@@@BUG 2608@@@ 
    336349    //auto a = [ 1, 2, 3 ]; 
    337350    int[] a = [ 1, 2, 3 ]; 
    338351    a.popBack; 
    339352    assert(a == [ 1, 2 ]); 
    340 
    341  
    342 void popBack(T)(ref T[] a) if (is(Unqual!T == char)) 
     353 
     354    static assert(!__traits(compiles, popBack!(immutable int[]))); 
     355
     356 
     357void popBack(A)(ref A a) 
     358if(is(A : const(char)[]) && notConst!A) 
    343359{ 
    344360    immutable n = a.length; 
    345361    const p = a.ptr + n; 
    346362    if (n >= 1 && (p[-1] & 0b1100_0000) != 0b1000_0000) 
    347363    { 
    348364        a = a[0 .. n - 1]; 
    349365    } 
    350366    else if (n >= 2 && (p[-2] & 0b1100_0000) != 0b1000_0000) 
    351367    { 
    352368        a = a[0 .. n - 2]; 
     
    369385{ 
    370386    string s = "hello\xE2\x89\xA0"; 
    371387    s.popBack(); 
    372388    assert(s == "hello", s); 
    373389 
    374390    string s3 = "\xE2\x89\xA0"; 
    375391    auto c = s3.back; 
    376392    assert(c == cast(dchar)'\u2260'); 
    377393    s3.popBack(); 
    378394    assert(s3 == ""); 
    379 
    380  
    381 void popBack(T)(ref T[] a) if (is(Unqual!T == wchar)) 
     395 
     396    static assert(!__traits(compiles, popBack!(immutable char[]))); 
     397
     398 
     399void popBack(A)(ref A a) 
     400if(is(A : const(wchar)[]) && notConst!A) 
    382401{ 
    383402    assert(a.length); 
    384403    if (a.length == 1) 
    385404    { 
    386405        a = a[0 .. 0]; 
    387406        return; 
    388407    } 
    389408    immutable c = a[$ - 2]; 
    390409    a = a[0 .. $ - 1 - (c >= 0xD800 && c <= 0xDBFF)]; 
    391410} 
    392411 
    393412unittest 
    394413{ 
    395414    wstring s = "hello\xE2\x89\xA0"; 
    396415    s.popBack(); 
    397416    assert(s == "hello"); 
     417 
     418    static assert(!__traits(compiles, popBack!(immutable wchar[]))); 
    398419} 
    399420 
    400421/** 
    401422Implements the range interface primitive $(D front) for built-in 
    402423arrays. Due to the fact that nonmember functions can be called with 
    403424the first argument using the dot notation, $(D array.front) is 
    404425equivalent to $(D front(array)). 
    405426 
    406427 
    407428Example: 
     
    830851    private static size_t newCapacity(size_t newlength) 
    831852    { 
    832853        long mult = 100 + (1000L) / (bsr(newlength * T.sizeof) + 1); 
    833854        // limit to doubling the length, we don't want to grow too much 
    834855        if(mult > 200) 
    835856            mult = 200; 
    836857        auto newext = cast(size_t)((newlength * mult + 99) / 100); 
    837858        return newext > newlength ? newext : newlength; 
    838859    } 
    839860 
     861    // Const fixing hack. 
     862    void put(Range)(Range items) 
     863    if(isInputRange!(Unqual!Range) && !isInputRange!Range) { 
     864        alias put!(Unqual!Range) p; 
     865        p(items); 
     866    } 
     867 
    840868/** 
    841869Appends an entire range to the managed array. 
    842870 */ 
    843871    void put(Range)(Range items) if (isInputRange!Range 
    844872            && is(typeof(Appender.init.put(items.front)))) 
    845873    { 
    846874        // note, we disable this branch for appending one type of char to 
    847875        // another because we can't trust the length portion. 
    848876        static if (!(isSomeChar!T && isSomeChar!(ElementType!Range) && 
    849877                     !is(Range == Unqual!(T)[])) && 
  • trunk/phobos/std/conv.d

    r2021 r2032  
    101101combination of qualifiers (mutable, $(D const), or $(D immutable)). 
    102102 
    103103Example: 
    104104---- 
    105105char[] a = "abc"; 
    106106auto b = to!dstring(a); 
    107107assert(b == "abc"w); 
    108108---- 
    109109 */ 
    110110T toImpl(T, S)(S s) if (!implicitlyConverts!(S, T) && isSomeString!T 
    111         && isInputRange!S && isSomeChar!(ElementType!S)) 
     111        && isInputRange!(Unqual!S) && isSomeChar!(ElementType!S)) 
    112112{ 
    113113    static if (isSomeString!S) 
    114114    { 
    115115        // string-to-string conversion 
    116116        static if (s[0].sizeof == T[0].sizeof) { 
    117117            // same width, only qualifier conversion 
    118118            enum tIsConst = is(T == const(char)[]) || is(T == const(wchar)[]) 
    119119                || is(T == const(dchar)[]); 
    120120            enum tIsInvariant = is(T == immutable(char)[]) 
    121121                || is(T == immutable(wchar)[]) || is(T == immutable(dchar)[]); 
     
    175175    } 
    176176} 
    177177 
    178178/** 
    179179Converts array (other than strings) to string. The left bracket, 
    180180separator, and right bracket are configurable. Each element is 
    181181converted by calling $(D to!T). 
    182182 */ 
    183183T toImpl(T, S)(S s, in T leftBracket = "[", in T separator = " ", 
    184184    in T rightBracket = "]") 
    185 if (isSomeString!T && !isSomeChar!(ElementType!S) && isInputRange!S) 
    186 
    187     alias Unqual!(typeof(T.init[0])) Char; 
    188 // array-to-string conversion 
    189     auto result = appender!(Char[])(); 
    190     result.put(leftBracket); 
    191     bool first = true; 
    192     for (; !s.empty; s.popFront()) 
    193     { 
    194         if (!first) 
    195         { 
    196             result.put(separator); 
    197         } 
    198         else 
    199         { 
    200             first = false; 
    201         } 
    202         result.put(to!T(s.front)); 
    203     } 
    204     result.put(rightBracket); 
    205     return cast(T) result.data; 
     185if (isSomeString!T && !isSomeChar!(ElementType!S) && 
     186(isInputRange!S || isInputRange!(Unqual!S))) 
     187
     188    static if(!isInputRange!S) { 
     189        alias toImpl!(T, Unqual!S) ti; 
     190        return ti(s, leftBracket, separator, rightBracket); 
     191    } else { 
     192        alias Unqual!(typeof(T.init[0])) Char; 
     193    // array-to-string conversion 
     194        auto result = appender!(Char[])(); 
     195        result.put(leftBracket); 
     196        bool first = true; 
     197        for (; !s.empty; s.popFront()) 
     198        { 
     199            if (!first) 
     200            { 
     201                result.put(separator); 
     202            } 
     203            else 
     204            { 
     205                first = false; 
     206            } 
     207            result.put(to!T(s.front)); 
     208        } 
     209        result.put(rightBracket); 
     210        return cast(T) result.data; 
     211    } 
    206212} 
    207213 
    208214/* 
    209215  Converting static arrays forwards to their dynamic counterparts. 
    210216 */ 
    211217T toImpl(T, S)(ref S s) 
    212218if (isStaticArray!S) 
    213219{ 
    214220    return toImpl!(T, typeof(s[0])[])(s); 
    215221} 
  • trunk/phobos/std/json.d

    r1925 r2032  
    5050                real                            floating; 
    5151                JSONValue[string]       object; 
    5252                JSONValue[]                     array; 
    5353        } 
    5454        JSON_TYPE                               type; 
    5555} 
    5656 
    5757/** 
    5858 Parses a serialized string and returns a tree of JSON values. 
    5959*/ 
    60 JSONValue parseJSON(T)(in T json, int maxDepth = -1) if(isInputRange!T) { 
     60JSONValue parseJSON(T)(T json, int maxDepth = -1) if(isInputRange!T) { 
    6161        JSONValue root = void; 
    6262        root.type = JSON_TYPE.NULL; 
    6363 
    6464        if(json.empty()) return root; 
    6565 
    6666        int depth = -1; 
    6767        dchar next = 0; 
    6868        int line = 1, pos = 1; 
    6969 
    7070        void error(string msg) { 
     
    420420        } 
    421421} 
    422422 
    423423version(unittest) import std.stdio; 
    424424 
    425425unittest { 
    426426        // An overly simple test suite, if it can parse a serializated string and 
    427427        // then use the resulting values tree to generate an identical 
    428428        // serialization, both the decoder and encoder works. 
    429429 
    430         immutable jsons = [ 
     430        auto jsons = [ 
    431431                `null`, 
    432432                `true`, 
    433433                `false`, 
    434434                `0`, 
    435435                `123`, 
    436436                `-4321`, 
    437437                `0.23`, 
    438438                `-0.23`, 
    439439                `""`, 
    440440                `1.223e+24`, 
  • trunk/phobos/std/numeric.d

    r1953 r2032  
    24602460 
    24612461/// ditto 
    24622462void inverseFft(Ret, R)(R range, Ret buf) { 
    24632463    mixin(MakeLocalFft); 
    24642464    return fftObj.inverseFft!(Ret, R)(range, buf); 
    24652465} 
    24662466 
    24672467 
    24682468unittest { 
    24692469    // Test values from R. 
    2470     const arr = [1,2,3,4,5,6,7,8]; 
    2471     const fft1 = fft(arr); 
     2470    auto arr = [1,2,3,4,5,6,7,8]; 
     2471    auto fft1 = fft(arr); 
    24722472    assert(approxEqual(map!"a.re"(fft1), 
    24732473        [36.0, -4, -4, -4, -4, -4, -4, -4])); 
    24742474    assert(approxEqual(map!"a.im"(fft1), 
    24752475        [0, 9.6568, 4, 1.6568, 0, -1.6568, -4, -9.6568])); 
    24762476 
    24772477    alias Complex!float C; 
    2478     const arr2 = [C(1,2), C(3,4), C(5,6), C(7,8), C(9,10), 
     2478    auto arr2 = [C(1,2), C(3,4), C(5,6), C(7,8), C(9,10), 
    24792479        C(11,12), C(13,14), C(15,16)]; 
    2480     const fft2 = fft(arr2); 
     2480    auto fft2 = fft(arr2); 
    24812481    assert(approxEqual(map!"a.re"(fft2), 
    24822482        [64.0, -27.3137, -16, -11.3137, -8, -4.6862, 0, 11.3137])); 
    24832483    assert(approxEqual(map!"a.im"(fft2), 
    24842484        [72, 11.3137, 0, -4.686, -8, -11.3137, -16, -27.3137])); 
    24852485 
    2486     const inv1 = inverseFft(fft1); 
     2486    auto inv1 = inverseFft(fft1); 
    24872487    assert(approxEqual(map!"a.re"(inv1), arr)); 
    24882488    assert(reduce!max(map!"a.im"(inv1)) < 1e-10); 
    24892489 
    2490     const inv2 = inverseFft(fft2); 
     2490    auto inv2 = inverseFft(fft2); 
    24912491    assert(approxEqual(map!"a.re"(inv2), map!"a.re"(arr2))); 
    24922492    assert(approxEqual(map!"a.im"(inv2), map!"a.im"(arr2))); 
    24932493 
    24942494    // FFTs of size 0, 1 and 2 are handled as special cases.  Test them here. 
    2495     const ushort[] empty; 
     2495    ushort[] empty; 
    24962496    assert(fft(empty) == null); 
    24972497    assert(inverseFft(fft(empty)) == null); 
    24982498 
    2499     const real[] oneElem = [4.5L]; 
    2500     const oneFft = fft(oneElem); 
     2499    real[] oneElem = [4.5L]; 
     2500    auto oneFft = fft(oneElem); 
    25012501    assert(oneFft.length == 1); 
    25022502    assert(oneFft[0].re == 4.5L); 
    25032503    assert(oneFft[0].im == 0); 
    25042504 
    2505     const oneInv = inverseFft(oneFft); 
     2505    auto oneInv = inverseFft(oneFft); 
    25062506    assert(oneInv.length == 1); 
    25072507    assert(approxEqual(oneInv[0].re, 4.5)); 
    25082508    assert(approxEqual(oneInv[0].im, 0)); 
    25092509 
    2510     immutable long[2] twoElems = [8, 4]; 
    2511     const twoFft = fft(twoElems[]); 
     2510    long[2] twoElems = [8, 4]; 
     2511    auto twoFft = fft(twoElems[]); 
    25122512    assert(twoFft.length == 2); 
    25132513    assert(approxEqual(twoFft[0].re, 12)); 
    25142514    assert(approxEqual(twoFft[0].im, 0)); 
    25152515    assert(approxEqual(twoFft[1].re, 4)); 
    25162516    assert(approxEqual(twoFft[1].im, 0)); 
    2517     const twoInv = inverseFft(twoFft); 
     2517    auto twoInv = inverseFft(twoFft); 
    25182518    assert(approxEqual(twoInv[0].re, 8)); 
    25192519    assert(approxEqual(twoInv[0].im, 0)); 
    25202520    assert(approxEqual(twoInv[1].re, 4)); 
    25212521    assert(approxEqual(twoInv[1].im, 0)); 
    25222522} 
    25232523 
    25242524// Swaps the real and imaginary parts of a complex number.  This is useful 
    25252525// for inverse FFTs. 
    25262526C swapRealImag(C)(C input) { 
    25272527    return C(input.im, input.re); 
  • trunk/phobos/std/range.d

    r2021 r2032  
    32953295    /// Ditto 
    32963296    Lockstep!(Ranges) lockstep(Ranges...)(Ranges ranges, StoppingPolicy s) 
    32973297    { 
    32983298        assert(0); 
    32993299    } 
    33003300} 
    33013301else 
    33023302{ 
    33033303    // Work around DMD bugs 4676, 4652. 
    33043304    auto lockstep(Args...)(Args args) 
    3305     if(allSatisfy!(isInputRange, Args) || ( 
    3306        allSatisfy!(isInputRange, Args[0..$ - 1]) && 
     3305    if(allSatisfy!(isInputRange, staticMap!(Unqual, Args)) || ( 
     3306       allSatisfy!(isInputRange, staticMap!(Unqual, Args[0..$ - 1])) && 
    33073307       is(Args[$ - 1] == StoppingPolicy)) 
    33083308    ) 
    33093309    { 
    33103310        static if(is(Args[$ - 1] == StoppingPolicy)) 
    33113311        { 
    33123312            alias args[0..$ - 1] ranges; 
    33133313            alias Args[0..$ - 1] Ranges; 
    33143314            alias args[$ - 1] stoppingPolicy; 
    33153315        } 
    33163316        else 
  • trunk/phobos/std/string.d

    r1993 r2032  
    534534 
    535535$(D CaseSensitive cs) controls whether the comparisons are case 
    536536sensitive or not. 
    537537 
    538538Returns: 
    539539 
    540540Index in $(D s) where $(D sub) is found, $(D -1) if not found. 
    541541 */ 
    542542 
    543543sizediff_t 
    544 indexOf(Char1, Char2)(in Char1[] s, in Char2[] sub, 
     544indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, 
    545545        CaseSensitive cs = CaseSensitive.yes) 
    546546{ 
    547547    if (cs == CaseSensitive.yes) 
    548548    { 
    549549        static if (Char1.sizeof == Char2.sizeof) 
    550550        { 
    551551            immutable result = s.length - std.algorithm.find(s, sub).length; 
    552552            return result == s.length ? -1 : result; 
    553553        } 
    554554        else 
  • trunk/phobos/std/xml.d

    r1934 r2032  
    118118Distributed under the Boost Software License, Version 1.0. 
    119119   (See accompanying file LICENSE_1_0.txt or copy at 
    120120         http://www.boost.org/LICENSE_1_0.txt) 
    121121*/ 
    122122module std.xml; 
    123123 
    124124import std.array; 
    125125import std.string; 
    126126import std.encoding; 
    127127 
    128 immutable cdata = "<![CDATA["; 
     128enum cdata = "<![CDATA["; 
    129129 
    130130/** 
    131131 * Returns true if the character is a character according to the XML standard 
    132132 * 
    133133 * Standards: $(LINK2 http://www.w3.org/TR/1998/REC-xml-19980210, XML 1.0) 
    134134 * 
    135135 * Params: 
    136136 *    c = the character to be tested 
    137137 */ 
    138138bool isChar(dchar c) // rule 2