Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 02, 2013 until strange behavior | ||||
---|---|---|---|---|
| ||||
Why char arr[3] = "abc"; arr[].until('b').front has type of dchar ??? |
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Sunday, 2 June 2013 at 13:20:32 UTC, Temtaime wrote: > Why > > char arr[3] = "abc"; > arr[].until('b').front has type of dchar ??? It is something wrong with ElementType template. char arr[4] = [1,2,3,0]; writeln(ElementType!(typeof(arr[])).stringof); // writes dchar |
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | Jack Applegame: > It is something wrong with ElementType template. > > char arr[4] = [1,2,3,0]; > writeln(ElementType!(typeof(arr[])).stringof); // writes dchar Try also ForeachType: http://dlang.org/phobos/std_traits.html#.ForeachType I agree it's often a pain in the ass, but technically it's not a bug, it's working as designed. Bye, bearophile |
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Sunday, 2 June 2013 at 13:30:16 UTC, bearophile wrote:
> I agree it's often a pain in the ass, but technically it's not a bug, it's working as designed.
Root is isNarrowString template.
Do you believe that "isNarrowString!(char[]) == true" technically is not a bug?
|
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | On 06/02/2013 06:43 AM, Jack Applegame wrote: > On Sunday, 2 June 2013 at 13:30:16 UTC, bearophile wrote: > >> I agree it's often a pain in the ass, but technically it's not a bug, >> it's working as designed. > > Root is isNarrowString template. > > Do you believe that "isNarrowString!(char[]) == true" technically is not > a bug? char and wchar arrays are narrow strings. Regardless, their element type is dchar. This causes confusion but makes sense because they are conceptually ranges of Unicode characters. There were long and heated discussions when this behavior was first proposed. Ali |
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | On Sunday, 2 June 2013 at 13:26:02 UTC, Jack Applegame wrote:
> It is something wrong with ElementType template.
ElementType works as intended.
As to whether that is a good idea… – just search the NG archives for "string range element type" or something like that.
David
|
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On Sunday, 2 June 2013 at 16:21:46 UTC, David Nadlinger wrote:
> On Sunday, 2 June 2013 at 13:26:02 UTC, Jack Applegame wrote:
> ElementType works as intended.
>
> As to whether that is a good idea… – just search the NG archives for "string range element type" or something like that.
(See also: ElementEncodingType)
|
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | > There were long and heated discussions when this behavior was first proposed.
Do you have a link to any of the discussions? This is one of the few things that irritates me in D in that I feel like I am fighting to control the type unnecessarily.
|
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Temtaime | On Sunday, June 02, 2013 15:20:31 Temtaime wrote: > Why > > char arr[3] = "abc"; > arr[].until('b').front has type of dchar ??? http://stackoverflow.com/questions/12288465 - Jonathan M Davis |
June 02, 2013 Re: until strange behavior | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Sunday, 2 June 2013 at 20:50:31 UTC, Jonathan M Davis wrote:
> http://stackoverflow.com/questions/12288465
Lets have string of chars, and it contains UTF-8 string.
Does front(str[]) automatically convert first unicode character to UTF-32 and returns it?
I made a test case and answer is: "Yes, it does!"
May be this make sense. But such implicit conversion confuses everyone whom I asked.
Therefore, string is not ordinary array (in Phobos context), but special array with special processing rules.
I'm moving from C++ and often ask myself: "why D has so much hidden confusing things?"
|
Copyright © 1999-2021 by the D Language Foundation