Re: Error: cannot deduce function from argument types

2018-05-05 Thread Sisor via Digitalmars-d-learn

On Saturday, 5 May 2018 at 17:06:13 UTC, Neia Neutuladh wrote:

On Saturday, 5 May 2018 at 16:42:12 UTC, Sisor wrote:
Error: template std.string.stripRight cannot deduce function 
from argument types


You used 
http://dpldocs.info/experimental-docs/std.string.stripRight.html


This function only takes one argument and strips whitespace.

You want 
http://dpldocs.info/experimental-docs/std.algorithm.mutation.stripRight.1.html


This function can take two arguments and strips the second from 
the first.


https://dlang.org/phobos/std_string.html#.stripRight has an 
overload with a second argument.


The std.algorithm.mutation version does only work with my second 
solution, which solves the problem. So thanks!


But I still don't understand the problem.


Error: cannot deduce function from argument types

2018-05-05 Thread Sisor via Digitalmars-d-learn

Hi,

I have a function:

string strippedString(ubyte[] block) {
return (cast(string)block).stripRight("\0");
}

With dmd it compiles, with ldc it produces the following error 
message:


Error: template std.string.stripRight cannot deduce function from 
argument types !()(string, string), candidates are:
/usr/lib/ldc/x86_64-linux-gnu/include/d/std/string.d(2902,6): 
   std.string.stripRight(Range)(Range str) if (isSomeString!Range 
|| isRandomAccessRange!Range && hasLength!Range && 
hasSlicing!Range && !isConvertibleToString!Range && 
isSomeChar!(ElementEncodingType!Range))
/usr/lib/ldc/x86_64-linux-gnu/include/d/std/string.d(3015,6): 
   std.string.stripRight(Range)(auto ref Range str) if 
(isConvertibleToString!Range)

ldmd2 failed with exit code 1.

Why?

The modified function does not even compile with either compiler:

string strippedString(ubyte[] block) {
return cast(string)( block.stripRight(0) );
}

How can I make the function more specific, so that the compiler 
knows, which option to take?


Kind regards,
Sisor