www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10262] New: utf.decodeFront doesn't work with a string slice

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10262

           Summary: utf.decodeFront doesn't work with a string slice
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: gdkslpmq spam4.me



The code

import std.utf;

void main() {
    string str = "asdf";
    size_t size;

    decodeFront(str[1..$], size);
}

fails to compile, with the error

test.d(8): Error: template std.utf.decodeFront does not match any function
template declaration. Candidates are:
/usr/include/d/std/utf.d(978):        std.utf.decodeFront(S)(ref S str, out
size_t numCodeUnits) if (!isSomeString!(S) && isInputRange!(S) &&
isSomeChar!(ElementType!(S)))
/usr/include/d/std/utf.d(1012):        std.utf.decodeFront(S)(ref S str, out
size_t numCodeUnits) if (isSomeString!(S))
/usr/include/d/std/utf.d(1038):        std.utf.decodeFront(S)(ref S str) if
(isInputRange!(S) && isSomeChar!(ElementType!(S)))
/usr/include/d/std/utf.d(978): Error: template std.utf.decodeFront cannot
deduce template function from argument types !()(string, ulong)

Casting str[1..$] to a string explicitly results in the same error. Putting the
slice outside the function call, like

string s2 = str[1..$];
decodeFront(s2, size);

Fixed the error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10262


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg gmx.com
         Resolution|                            |INVALID



PDT ---
It's not supposed to work with a slice like that. It accepts arguments by ref
and pops off elements from the range that it's given, so it requires that you
give it an lvalue, which is what you did with

string s2 = str[1..$];
decodeFront(s2, size);

It accepted rvalues in 2.062, but that resulted in very inconsistent and
potentially buggy behavior (depending on the type of range), so it now accepts
the range by ref.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10262




Ah sorry, my mistake.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2013