View source code
Display the source code in std/algorithm/mutation.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.algorithm.mutation.reverse

Reverses r in-place. Performs r.length / 2 evaluations of swap. UTF sequences consisting of multiple code units are preserved properly.

Range reverse(Range) (
  Range r
)
if (isBidirectionalRange!Range && (hasSwappableElements!Range || hasAssignableElements!Range && hasLength!Range && isRandomAccessRange!Range || isNarrowString!Range && isAssignable!(ElementType!Range)));

Parameters

NameDescription
r a bidirectional range with either swappable elements, a random access range with a length member, or a narrow string

Returns

r

Note

When passing a string with unicode modifiers on characters, such as \u0301, this function will not properly keep the position of the modifier. For example, reversing ba\u0301d ("bád") will result in d\u0301ab ("d́ab") instead of da\u0301b ("dáb").

See Also

std.range.retro for a lazy reverse without changing r

Example

int[] arr = [ 1, 2, 3 ];
writeln(arr.reverse); // [3, 2, 1]

Example

char[] arr = "hello\U00010143\u0100\U00010143".dup;
writeln(arr.reverse); // "\U00010143\u0100\U00010143olleh"

Authors

Andrei Alexandrescu

License

Boost License 1.0.