Summary: std.string.reversed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from 2012-01-12 10:47:00 PST ---
I suggest to add a reversed() function to std.string (the "-ed" suffix is a
Python convention that means it's not an in-place function. It creates a copy
of the input data, works on it, and returns it):

import std.stdio, std.algorithm, std.traits;

immutable(T)[] reversed(T)(immutable(T[]) s)
@safe pure /*nothrow*/ if (isSomeChar!T) {
    auto sr = s.dup; // druntime BUG not nothrow
    return sr; // Implicit immutable cast because it's pure.

unittest {
    assert("red".reversed() == "der");  // UTF-8
    assert("red"w.reversed() == "der"); // UTF-16
    assert("red"d.reversed() == "der"); // UTF-32

It's not nothrow yet because someArray.dup is not nothrow yet.

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

Reply via email to