How to reverse char[]?
Timon Gehr
timon.gehr at gmx.ch
Tue Feb 7 17:36:23 PST 2012
On 02/08/2012 02:29 AM, H. S. Teoh wrote:
> Hi all,
>
> I'm trying to reverse a character array. Why doesn't the following work?
>
> import std.algorithm;
> void main() {
> char[] array = ['a', 'b', 'c'];
> reverse(array);
> }
>
> I get:
>
> Error: template std.algorithm.reverse(Range) if (isBidirectionalRange!(Range)&& hasSwappableElements!(Range)) does not match any function template declaration
> Error: template std.algorithm.reverse(Range) if (isBidirectionalRange!(Range)&& hasSwappableElements!(Range)) cannot deduce template function from argument types !()(char[])
>
>
> T
>
char[] is handled by Phobos as a range of dchar, ergo it does not have
swappable elements. Apparently there is no template specialisation of
'reverse' that handles narrow strings, you might want to file an
enhancement request.
More information about the Digitalmars-d-learn
mailing list