Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 07, 2015 Strange behavior std.range.takeNone | ||||
---|---|---|---|---|
| ||||
Hi, Is it OK? ----- import std.stdio : writeln; import std.range : takeNone; void main() { auto s = takeNone("test"); s ~= 5; writeln(s); // prints ♣ } ----- Windows 8.1 x64, DMD 2.067.0 |
April 07, 2015 Re: Strange behavior std.range.takeNone | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Tuesday, 7 April 2015 at 02:24:00 UTC, Dennis Ritchie wrote:
> Is it OK?
Although, perhaps, everything is fine. I just thought that creates takeNone not string type string, and the string array of type string[].
import std.stdio : writeln;
void main() {
string s;
s ~= 5;
writeln(s); // prints ♣
}
So I mixed up with this case. Everything is OK.
import std.range : takeNone;
void main() {
auto s = takeNone(["test"]);
// s ~= 5; // Error: cannot append type int to type string[]
}
|
April 07, 2015 Re: Strange behavior std.range.takeNone | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | Yes it is.
takeNone() take a char from a string.
So you are going to append a char (with code 5) on the next line.
If you replace that line with:
s ~= 65;
it will print "A". (65 is ascii code for letter 'A')
On Tuesday, 7 April 2015 at 02:24:00 UTC, Dennis Ritchie wrote:
> Hi,
> Is it OK?
>
> -----
> import std.stdio : writeln;
> import std.range : takeNone;
>
> void main() {
>
> auto s = takeNone("test");
>
> s ~= 5;
>
> writeln(s); // prints ♣
> }
> -----
> Windows 8.1 x64, DMD 2.067.0
|
April 07, 2015 Re: Strange behavior std.range.takeNone | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 7 April 2015 at 08:49:58 UTC, Andrea Fontana wrote:
> Yes it is.
>
> takeNone() take a char from a string.
>
> So you are going to append a char (with code 5) on the next line.
> If you replace that line with:
>
> s ~= 65;
>
> it will print "A". (65 is ascii code for letter 'A')
Thanks. I am aware :)
|
Copyright © 1999-2021 by the D Language Foundation