digitalmars.D - string "char[]" initialization
- Tyro (12/12) Dec 20 2004 The following is minor in the grand scheme of things. However, methinks
- Vathix (6/18) Dec 20 2004 Methinks the D way shows you what's really going on..
- Tyro (8/32) Dec 20 2004 You've got a point there Chris. I didn't it too difficult
- Tyro (6/11) Dec 20 2004 Ok I'll wait until I wake up before I make anymore posts.
- Russ Lewis (10/16) Dec 20 2004 Ok, I'm not exactly recommending that you use this, because it's hardly
- Tyro (2/18) Dec 20 2004
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/17) Dec 20 2004 Does the size really matter? :)
- Tyro (6/23) Dec 20 2004 Sorry, size wasn't a good choice of words there.
- David Medlock (6/24) Dec 20 2004 This is not a valid comparison, imo.
- Ben Hinkle (10/34) Dec 20 2004 Since char[] in D is supposed to fill the same roll as std::string in C+...
The following is minor in the grand scheme of things. However, methinks it important enough to warrant attention sometime in D future. The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better. Andrew
Dec 20 2004
On Mon, 20 Dec 2004 07:02:24 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:The following is minor in the grand scheme of things. However, methinks it important enough to warrant attention sometime in D future. The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better. AndrewMethinks the D way shows you what's really going on.. You could also use an initializer instead of using length, int size = 30; char fill = '*'; char[] dstr = new char[size]; dstr[] = fill;
Dec 20 2004
In article <opsja3isbqkcck4r tc3-ppp015.dialup.wzrd.com>, Vathix says...On Mon, 20 Dec 2004 07:02:24 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:You've got a point there Chris. I didn't it too difficult a concept to understand. But yes, I will admit there is ambiguity in the D way.The following is minor in the grand scheme of things. However, methinks it important enough to warrant attention sometime in D future. The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better. AndrewMethinks the D way shows you what's really going on..You could also use an initializer instead of using length, int size = 30; char fill = '*'; char[] dstr = new char[size]; dstr[] = fill;Thanks for the pointer! I didn't think about that. Andrew --- [acedwards] at [ieee] dot [org]
Dec 20 2004
In article <cq6nas$8fa$1 digitaldaemon.com>, Tyro says...In article <opsja3isbqkcck4r tc3-ppp015.dialup.wzrd.com>, Vathix says...[snip]You've got a point there Chris. I didn't it too difficult a concept to understand. But yes, I will admit there is ambiguity in the D way.Ok I'll wait until I wake up before I make anymore posts. What I meant to say was: I didn't think it too difficult a concept to understand. But yes, I will admit that there is no ambiguity in the D way.
Dec 20 2004
Vathix wrote:Methinks the D way shows you what's really going on.. You could also use an initializer instead of using length, int size = 30; char fill = '*'; char[] dstr = new char[size]; dstr[] = fill;Ok, I'm not exactly recommending that you use this, because it's hardly readable, but you can actually do it all in one statement, like this:char[] dstr = ((new char[30])[] = '*');The simple soltuion to ths, IMHO, is to implement it in a library, so that it looks like C++: char[] fill_string(int len, char c) { char[] ret = new char[len]; ret[] = c; return ret; }
Dec 20 2004
In article <cq6pc7$anu$1 digitaldaemon.com>, Russ Lewis says...Vathix wrote:Suddenly things don't look all that dark anymore. Thanks!Methinks the D way shows you what's really going on.. You could also use an initializer instead of using length, int size = 30; char fill = '*'; char[] dstr = new char[size]; dstr[] = fill;Ok, I'm not exactly recommending that you use this, because it's hardly readable, but you can actually do it all in one statement, like this:char[] dstr = ((new char[30])[] = '*');The simple soltuion to ths, IMHO, is to implement it in a library, so that it looks like C++: char[] fill_string(int len, char c) { char[] ret = new char[len]; ret[] = c; return ret; }
Dec 20 2004
Tyro wrote:The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better.Does the size really matter? :) In Perl it's: $pstr = '*' x 30; --anders
Dec 20 2004
In article <cq6har$23n$1 digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...Tyro wrote:Sorry, size wasn't a good choice of words there. length would have been much better. And no it doesn't matter. Just as long as I can set some length and fill it up with some characters.The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better.Does the size really matter? :)In Perl it's: $pstr = '*' x 30; --anders
Dec 20 2004
Tyro wrote:The following is minor in the grand scheme of things. However, methinks it important enough to warrant attention sometime in D future. The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better. AndrewThis is not a valid comparison, imo. You are comparing standard D with the STL string class. Once DTL is finished we can compare code. Cheers, Ash
Dec 20 2004
"David Medlock" <amedlock nospam.org> wrote in message news:cq6poj$avn$1 digitaldaemon.com...Tyro wrote:Since char[] in D is supposed to fill the same roll as std::string in C++ then I'd say the comparison is valid. But to me the D way is so close to the C++ way that it doesn't matter for the rare instances a fill value is actually needed. Then again maybe Tyro has tons of places in his code where he need a fill value, but I can't really imagine why it would be very common. A helper routine to do in 10 keystrokes what the builtins can do in 20 had better be used often in order to justify its existence. -BenThe following is minor in the grand scheme of things. However, methinks it important enough to warrant attention sometime in D future. The C++ way: int size = 30; char fill = '*'; std::string cstr(size, fill); The D way: int size = 30; char fill = '*'; char[] dstr; dstr.length = size; dstr[] = fill; Methinks the C++ way is better. AndrewThis is not a valid comparison, imo. You are comparing standard D with the STL string class. Once DTL is finished we can compare code. Cheers, Ash
Dec 20 2004