appender!(dchar[]) put fail
Quentin Ladeveze via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 13 05:43:37 PDT 2015
On Saturday, 13 June 2015 at 12:02:10 UTC, kerdemdemir wrote:
>
>> The problem is that your appender is a char appender, and you
>> try to put a dstring into it. Replace :
>>
>> charAppender.put(totalStr);
>>
>> by :
>>
>> foreach(elem; totalStr){
>> charAppender.put(elem);
>> }
>>
>> elem will be a dchar, so it will work.
>
>
> But I can see in the example of
> array.appander(http://dlang.org/phobos/std_array.html#appender)
>
> int[] a = [ 1, 2 ];
> auto app2 = appender(a);
> app2.put(3);
> app2.put([ 4, 5, 6 ]); ---> appender accepts another array.
>
> Why this is not same with dchar ?
It is the same, but totalStr is not a dchar[]. It's a Result (a
type internal to the chain function ) which is a range. The
foreach loop iterates over Result, which returns dchar[].
So if you try to do something like that :
charAppender.put(totalStr.array), it won't work because
totalStr.array is a dchar[][].
More information about the Digitalmars-d-learn
mailing list