Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 13, 2015 char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Hello, everyone! I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply the method .dup each substring to make them work :) I understand that the type of `string[]` to D is a simple data type than `char[][]`, but it seems to me that the problem is solved in C++: std::vector<std::string> stdArray; I wish to propose the creation of new types of data D: str, wstr, dstr, which will be the analogs of C++ `std::vector<std::string>`. I do not know whether it is possible to create in the D, but I want to know where I write a sentence? Can I file a dmd-issue, or should I create a DIP, because it is too big improvement? |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: > I wish to propose the creation of new types of data D: str, wstr, dstr, which will be the analogs of C++ `std::vector<std::string>`. Ie str, wstr, dstr be mutable counterparts immutable strings respectively str (mutable(char[])), wstr (mutable(wchar[])), dstr (mutable(dchar[])). In C++: std::vector<std::string> str[], wstr[], dstr[] in C++: std::vector<std::vector<std::string> > |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: > Hello, everyone! > > I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. > > I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply the method .dup each substring to make them work :) Huh? You mean with string literals? That would be a rather silly reason to avoid `char[]`. Please show an example of .dup you'd like to avoid. > I understand that the type of `string[]` to D is a simple data type than `char[][]`, Are you saying that `string[]` is simpler than `char[][]`? That's not true: `string` is an alias for `immutable(char)[]`, so `string[]` is the same as `immutable(char)[][]`. > but it seems to me that the problem is solved in C++: > std::vector<std::string> stdArray; > > I wish to propose the creation of new types of data D: str, wstr, dstr, which will be the analogs of C++ `std::vector<std::string>`. Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: > Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. Do you like to write? char[][] strArray = ["foo".dup, "bar".dup, "baz".dup]; I suggest that such an option: str[] strArray = ["foo", "bar", "baz"]; On Saturday, 13 June 2015 at 15:38:31 UTC, Dennis Ritchie wrote: > Ie str, wstr, dstr be mutable counterparts immutable strings respectively str (mutable(char[])), wstr (mutable(wchar[])), dstr (mutable(dchar[])). In C++: > std::vector<std::string> std::string in C++. > str[], wstr[], dstr[] in C++: > std::vector<std::vector<std::string> > std::vector<string> in C++. |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: > Huh? You mean with string literals? That would be a rather silly reason to avoid `char[]`. Please show an example of .dup you'd like to avoid. Yes, string literals. >> I understand that the type of `string[]` to D is a simple data type than `char[][]`, > > Are you saying that `string[]` is simpler than `char[][]`? That's not true: `string` is an alias for `immutable(char)[]`, so `string[]` is the same as `immutable(char)[][]`. On Monday, 18 May 2015 at 13:14:38 UTC, Steven Schveighoffer wrote: > But really, a string is immutable. There's not a way around that. A string is the most basic level of array primitive, not even mutable arrays of non-char types have that, and it's an annoyance. From there, you have to build the data out of ROM into the heap. http://forum.dlang.org/post/mjctql$j19$1@digitalmars.com |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote:
> Please show an example of .dup you'd like to avoid.
For example, if you need to create a five-dimensional array of strings :)
|
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Saturday, 13 June 2015 at 15:58:44 UTC, Dennis Ritchie wrote: > On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: >> Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. > > Do you like to write? > char[][] strArray = ["foo".dup, "bar".dup, "baz".dup]; Ok. That's all you're on about? Basically you'd like this: char[] s = "foo"; and this: char[][] a = [["foo"]]; etc. Yeah, that would be neat. But typing out ".dup" isn't that bad, and converting a `string[]` to a `char[][]` is simple: import std.conv: to; auto a = ["foo"].to!(char[][]); > I suggest that such an option: > str[] strArray = ["foo", "bar", "baz"]; I don't see how adding a new builtin type `str` would solve anything. |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Saturday, 13 June 2015 at 16:09:58 UTC, Dennis Ritchie wrote: > On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: [...] >> Are you saying that `string[]` is simpler than `char[][]`? That's not true: `string` is an alias for `immutable(char)[]`, so `string[]` is the same as `immutable(char)[][]`. > > On Monday, 18 May 2015 at 13:14:38 UTC, Steven Schveighoffer wrote: >> But really, a string is immutable. There's not a way around that. A string is the most basic level of array primitive, not even mutable arrays of non-char types have that, and it's an annoyance. From there, you have to build the data out of ROM into the heap. > http://forum.dlang.org/post/mjctql$j19$1@digitalmars.com I don't understand what you're trying to say with that quote. |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: >> Do you like to write? >> char[][] strArray = ["foo".dup, "bar".dup, "baz".dup]; > > Ok. That's all you're on about? Basically you'd like this: > char[] s = "foo"; > and this: > char[][] a = [["foo"]]; > etc. Yes. That's right, and not otherwise :) > Yeah, that would be neat. But typing out ".dup" isn't that bad, and converting a `string[]` to a `char[][]` is simple: > import std.conv: to; > auto a = ["foo"].to!(char[][]); Yes, but it is not suitable for multidimensional array of strings. >> I suggest that such an option: >> str[] strArray = ["foo", "bar", "baz"]; > > I don't see how adding a new builtin type `str` would solve anything. And why in C++ is running `std::vector<std::string>` ? Really in D can not do something like that? Maybe a new type will not solve anything, but there should be other ways to do in D analogue strings of C++. On Saturday, 13 June 2015 at 16:22:44 UTC, anonymous wrote: > I don't understand what you're trying to say with that quote. I would not say `simpler`, and `basic`. I just forgot the right word, because my English is not good enough. |
June 13, 2015 Re: char[][] to std::vector<std::string> - DIP or dmd-issue? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Saturday, 13 June 2015 at 17:02:06 UTC, Dennis Ritchie wrote: > On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: [...] >> Yeah, that would be neat. But typing out ".dup" isn't that bad, and converting a `string[]` to a `char[][]` is simple: >> import std.conv: to; >> auto a = ["foo"].to!(char[][]); > > Yes, but it is not suitable for multidimensional array of strings. Please show how it is not. Seems to work just fine. [...] > And why in C++ is running `std::vector<std::string>` ? > Really in D can not do something like that? > > Maybe a new type will not solve anything, but there should be other ways to do in D analogue strings of C++. Your definitions of "something like that" and "other ways" are unreasonably narrow, in my opinion. Typing out ".dup" is D's way to do mutable strings. You just don't like it. |
Copyright © 1999-2021 by the D Language Foundation