http://d.puremagic.com/issues/show_bug.cgi?id=7281
Summary: std.string.reversed Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nob...@puremagic.com ReportedBy: bearophile_h...@eml.cc --- Comment #0 from bearophile_h...@eml.cc 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 sr.reverse(); 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: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------