appender!(dchar[]) put fail
Quentin Ladeveze via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 13 04:23:34 PDT 2015
On Saturday, 13 June 2015 at 10:45:58 UTC, kerdemdemir wrote:
> I have two strings(stringB,stringC) which I need to
> repeat(bCount times, cCountTimes) and then chain.
>
> auto charAppender = appender!(dchar[]);
> auto totalStr =
> stringB.repeat(bCount).chain(stringC.repeat(cCount));
>
> This compiles and works ok,
> But when I try to append new string to charAppender :
>
> charAppender.put(totalStr);
> Error: template std.array.join cannot deduce function from
> argument types
>
> I tried:
> charAppender.put(totalStr.array());
> charAppender.data.chain(totalStr);
> charAppender.data.chain(totalStr.array()); etc...
>
> I always get compile errors.
> Do you have any idea or fix about that?
>
> Also what is the difference between algorithm.joiner without
> seperator and range.chain?
>
> ////////////////////////////////////////////////////////////////////////////
> As requested before, this time I will copy full code,
> ////////////////////////////////////////////////////////////////////////////
> int[dchar] mapA;
> int includeCounter(T)(T tuple)
> {
> int curMax = 100000;
>
> foreach ( elem ; tuple )
> {
> int numberInA = 0;
> if (elem[0] in mapA)
> numberInA = mapA[elem[0]] ;
> else
> {
> curMax = 0;
> break;
> }
>
> if ( numberInA < elem[1] )
> {
> curMax = 0;
> break;
> }
> else
> {
> auto newCount = numberInA / elem[1];
> if ( newCount < curMax )
> curMax = newCount;
> }
> }
> if (curMax > 0)
> {
> foreach ( elem ; tuple )
> {
> mapA[elem[0]] -= curMax;
> }
> }
>
> return curMax;
> }
>
> void readInput()
> {
> size_t lineSize;
>
> auto stringA = stdin.readln.chomp().map!( a =>
> to!dchar(a)).array();
> auto stringB = stdin.readln.chomp().map!( a =>
> to!dchar(a)).array();
> auto stringC = stdin.readln.chomp().map!( a =>
> to!dchar(a)).array();
>
> foreach ( elem ; stringA)
> mapA[elem]++;
>
> auto tupleB = stringB.group();
> auto tupleC = stringC.group();
>
> auto bCount = includeCounter( tupleB );
> auto cCount = includeCounter( tupleC );
>
> auto charAppender = appender!(dchar[]);
> foreach ( elem ; mapA.keys)
> {
> int* count = &mapA[elem];
> if ( *count > 0)
> {
> while((*count)--)
> charAppender.put(elem) ;
> }
> }
>
> auto totalStr =
> stringB.repeat(bCount).chain(stringC.repeat(cCount));
> charAppender.put(totalStr);
> }
>
> void main( string[] args )
> {
> readInput();
> }
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.
More information about the Digitalmars-d-learn
mailing list