[Issue 11494] std.array.appender is not nothrow

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 13 10:17:39 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11494



--- Comment #4 from monarchdodra at gmail.com 2013-11-13 10:17:38 PST ---
(In reply to comment #3)
> I'm not sure what's going on here, maybe it is trying to parse the string. But
> the appender issue itself might be invalid and/or already fixed in the newest
> dmd though.

It's trying to parse the string.

If you want to "interpret" the string as ubytes, you can use
"std.string.representation". This will "reinterpret" your string according to
its type:
string => immutable(ubyte)[]
wchar[] => ushort[]
dchar[] => uint[]

However, this will not *allocate* a new array, and it is not safe either. It
*is* nothrow though. If you want a new array, I'd recommend adding a ".dup",
but that's not nothrow.

I don't know any 1 liners that are @safe, pure and nothrow. My recommendation
would be to make an explicit trusted helper that will do it for you. Eg:

ubyte[] str2ubyte(in char[] str) pure nothrow
{
    auto arr = uninitializedArray!(ubyte[])(str.length);
    arr[]=str.representation()[];
    return arr;
}

You could templatize too, just like representation, so as to work on any width.

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


More information about the Digitalmars-d-bugs mailing list