--- Comment #12 from 2011-10-28 17:33:16 PDT ---
An use case for sorted(). I have to create a function foo() with a int[]
argument. Unless foo() is performance-critical the usual API requirements ask
for its arguments to be constant (in), to make the program less bug-prone.
Inside foo() I need to sort the a copy of items, and then I don't need to
modify this array, so I'd like this array copy too to be const. This is an
implementation that currently works:

import std.algorithm, std.exception;
void foo(in int[] unsortedData) {
    int[] tmpData_ = unsortedData.dup;
    const(int[]) data = assumeUnique(tmpData_);
    // Use array 'data' here.
void main() {}

assumeUnique is not safe, and the tmpData_ name is present in the scope still
(despite assumeUnique has turned its length to zero, this improves the
situation a little).

With a pure sorted(), the code becomes more clean and safe:

import std.algorithm;
void foo(in int[] unsortedData) pure {
    const(int[]) data = sorted(unsortedData);
    // Use array 'data' here.
void main() {}

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to