syntax for calling to with a getter as source argument
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 14 16:04:43 PDT 2014
On Mon, Jul 14, 2014 at 09:12:30PM +0000, Klb via Digitalmars-d-learn wrote:
> hello what is the right syntax for this:
>
> ----------------------------------------------------
> import std.stdio, std.conv;
>
> void main(string args[])
> {
> ubyte[3] src = [0, 1, 2];
> string trg = "";
>
> @property ubyte[3] srcAsProp(){return src;}
>
> // Error: template std.conv.to cannot deduce function from argument types
> // !(string)(ubyte[3]), candidates are:
> trg = to!(string)(srcAsProp());
> }
> ----------------------------------------------------
>
> In a real-world application I'd use an intermediate value but I'd like
> to know If it's possible...The strange fact is that it doesn't trig an
> error if src is a dyn. array. (if you remove the 3 from [3] then it
> passes).
You need to slice the static array:
trg = to!string(srcAsProp()[]);
Or, if you like to use UFCS (Uniform Function Call Syntax):
trg = srcAsProp()[].to!string;
You might want to file an enhancement request to improve the error
message, though -- it's not very helpful as it stands.
T
--
Trying to define yourself is like trying to bite your own teeth. -- Alan Watts
More information about the Digitalmars-d-learn
mailing list