join of range of ranges?

monarch_dodra monarchdodra at gmail.com
Sun Sep 22 13:46:37 PDT 2013


On Sunday, 22 September 2013 at 20:27:01 UTC, bearophile wrote:
> Peter Alexander:
>
>> The problem is that you are trying to map a range of range of 
>> chars with a range of dchars.
>>
>> auto r2 = [1, 2]
>>              .map!(x => [1, 2].map!(y => cast(dchar)'*'))
>>              .join("_");
>>
>> This works.
>
> I see, thank you. When I ask a question it seems my brain 
> switches off a bit :-)
>
>
>> I really wish character literals in D where always dchar.
>
> This is supported:
>
> void main() {
>     auto s1 = "hello"w;
>     auto s2 = "hello"d;
> }
>
>
> So, what about adding support for this?
>
> void main() {
>     auto c1 = 'X'w;
>     auto c2 = 'X'd;
>     static assert(is(typeof(c1) == wchar));
>     static assert(is(typeof(c2) == dchar));
> }
>
>
> Bye,
> bearophile

Even "hello"c is supported actually :) It can make a difference 
if you *don't* want your string implicitly promoted on 
declaration. EG:

dstring ds1 = "hello"; //Fine
dstring ds2 = "hello"c; //Nope.

As for allowing 'X'w, I think the rationale is that a cast will 
get you the same result (not so with string literals).


More information about the Digitalmars-d-learn mailing list