digitalmars.D.learn - std.utf.decode("dlang", 1)
- Algo (16/16) Sep 17 2014 void main()
- Algo (2/18) Sep 17 2014 rvalues cannot be ref it seems
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (14/34) Sep 17 2014 Yes. Interestingly, in D rvalues cannot be bound even to const ref.
- AsmMan (12/28) Sep 18 2014 I was having same issue a while ago. But I realized I was using
void main() { import std.utf; decode("dlang", 1); } Error: template std.utf.decode cannot deduce function from argument types !()(string, int), candidates are: D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(924): std.utf.decode(S)(auto ref S str, ref size_t index) if (!isSomeString!S && isRandomAccessRange!S && hasSlicing!S && hasLength!S && isSomeChar!(ElementType!S)) D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(942): std.utf.decode(S)(auto ref S str, ref size_t index) if (isSomeString!S) why doesn't "decode(S)(auto ref S str, ref size_t index) if (isSomeString!S)" correspond?
Sep 17 2014
On Thursday, 18 September 2014 at 06:09:54 UTC, Algo wrote:void main() { import std.utf; decode("dlang", 1); } Error: template std.utf.decode cannot deduce function from argument types !()(string, int), candidates are: D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(924): std.utf.decode(S)(auto ref S str, ref size_t index) if (!isSomeString!S && isRandomAccessRange!S && hasSlicing!S && hasLength!S && isSomeChar!(ElementType!S)) D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(942): std.utf.decode(S)(auto ref S str, ref size_t index) if (isSomeString!S) why doesn't "decode(S)(auto ref S str, ref size_t index) if (isSomeString!S)" correspond?rvalues cannot be ref it seems
Sep 17 2014
On 09/17/2014 11:23 PM, Algo wrote:On Thursday, 18 September 2014 at 06:09:54 UTC, Algo wrote:Yes. Interestingly, in D rvalues cannot be bound even to const ref. void main() { import std.stdio; import std.utf; size_t index = 1; dchar decoded = decode("dlang", index); writefln("decoded '%s', next character is at index %s.", decoded, index); } The output: decoded 'l', next character is at index 2. Alivoid main() { import std.utf; decode("dlang", 1); } Error: template std.utf.decode cannot deduce function from argument types !()(string, int), candidates are: D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(924): std.utf.decode(S)(auto ref S str, ref size_t index) if (!isSomeString!S && isRandomAccessRange!S && hasSlicing!S && hasLength!S && isSomeChar!(ElementType!S)) D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(942): std.utf.decode(S)(auto ref S str, ref size_t index) if (isSomeString!S) why doesn't "decode(S)(auto ref S str, ref size_t index) if (isSomeString!S)" correspond?rvalues cannot be ref it seems
Sep 17 2014
On Thursday, 18 September 2014 at 06:09:54 UTC, Algo wrote:void main() { import std.utf; decode("dlang", 1); } Error: template std.utf.decode cannot deduce function from argument types !()(string, int), candidates are: D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(924): std.utf.decode(S)(auto ref S str, ref size_t index) if (!isSomeString!S && isRandomAccessRange!S && hasSlicing!S && hasLength!S && isSomeChar!(ElementType!S)) D:\msc\D\dmd2\windows\bin\..\..\src\phobos\std\utf.d(942): std.utf.decode(S)(auto ref S str, ref size_t index) if (isSomeString!S) why doesn't "decode(S)(auto ref S str, ref size_t index) if (isSomeString!S)" correspond?I was having same issue a while ago. But I realized I was using function in the wrong way with string type and passing a size_t in the 2th argument. You can see use of decode(val, size) in the standard library but call it in your code result in an error. it worked: string s = readText("file"); decode(cast(ubyte[]) s); I'm not sure why you're trying to pass a string literal as argument because it does need a memory location to change to new memory location, where bytes skiped end. That's why it does use ref.
Sep 18 2014