A small trouble with std.range.indexed

bearophile bearophileHUGS at lycos.com
Thu Sep 8 00:33:24 PDT 2011


std.range.indexed of DMD 2.055 is very nice. But it signature shows constraints that I have had problems to work with, maybe the error is just mine, I don't know:


import std.algorithm, std.range, std.array;
void main() {
    auto data = [7, 6, 5, 4, 3, 2, 1, 0];
    auto indices = [6, 1, 7];

    //auto idxSet = array(uniq(indices.sort())); // OK
    auto idxSet = uniq(indices.sort()); // not OK?

    // std.range.indexed() constraints
    static assert(isInputRange!(typeof(idxSet))); // OK
    static assert( is(typeof((int[]).init[ElementType!(typeof(idxSet)).init])) ); // OK

    sort(indexed(data, idxSet));
    assert(data == [7, 0, 5, 4, 3, 2, 1, 6]);
}


Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list