appender!(dchar[]) put fail
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 13 16:03:44 PDT 2015
On 06/13/2015 04:23 AM, Quentin Ladeveze 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.
To answer Erdem's later question, loops with side effects can be
replaced with std.algorithm.each:
totalStr.each!(elem => charAppender.put(elem));
One issue with that method that I am frequently reminded of is that
although the lambda's => syntax is by definition a return statement,
'each' does not do anything with the returned value. (Regardless of
whether the lambda returns anything or not.)
Ali
More information about the Digitalmars-d-learn
mailing list