[Issue 7281] std.string.reversed

2012-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7281



--- Comment #1 from bearophile_h...@eml.cc 2012-01-12 10:53:09 PST ---
This function is handy because the alternative is to use code like this, that
is much longer (3 or 4 lines long), it's not a single expression, and it needs
two copies of the original string (or a copy and a cast, or a copy and one
assume unique):


import std.algorithm: reverse;
void main() {
string s = red;
char[] s1 = s.dup;
s1.reverse();
string sr = s1.idup;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7281] std.string.reversed

2012-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7281


Jonathan M Davis jmdavisp...@gmx.com changed:

   What|Removed |Added

 CC||jmdavisp...@gmx.com


--- Comment #2 from Jonathan M Davis jmdavisp...@gmx.com 2012-01-12 15:54:46 
PST ---
Your example is not the shortest way of doing this. The typical way would be

array(retro(str));

which _is_ an expression and almost as concise as

reversed(str);

I question that adding another function is worth it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7281] std.string.reversed

2012-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7281


Andrej Mitrovic andrej.mitrov...@gmail.com changed:

   What|Removed |Added

 CC||andrej.mitrov...@gmail.com


--- Comment #3 from Andrej Mitrovic andrej.mitrov...@gmail.com 2012-01-12 
16:06:50 PST ---
(In reply to comment #2)
 Your example is not the shortest way of doing this. The typical way would be
 
 array(retro(str));
 
 which _is_ an expression and almost as concise as
 

You can't assign that back to a string:

string str = foo;
str = array(retro(str)).idup;  // error

I don't know why array insists on creating dchar[] instead of char[]? Shorter
example:

char[] duped = array(str);  // error: can't convert dchar[] to char[]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7281] std.string.reversed

2012-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7281



--- Comment #4 from Jonathan M Davis jmdavisp...@gmx.com 2012-01-12 16:39:38 
PST ---
Ah, yes. I forgot about that. array generates a dchar[], because retro returns
a range of dchar, not a string, and array returns an array with the same
element type as the range passed to it. The correct way to do it then would be

to!string(retro(str))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7281] std.string.reversed

2012-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7281


bearophile_h...@eml.cc changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||WONTFIX


--- Comment #5 from bearophile_h...@eml.cc 2012-01-12 18:23:10 PST ---
(In reply to comment #4)

 to!string(retro(str))

Or better text(retro(str)) or wtext(retro(str)) or dtext(retro(str)).

Or even  to!(typeof(str))(retro(str))  if you want to be generic.

I think this is a good enough solution, so I close this issue. Thank you
Jonathan.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---