digitalmars.D.bugs - [Issue 12489] New: std.bitmanip byte swapping routines should be partially instantiable
- d-bugmail puremagic.com (44/44) Mar 29 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12489
- d-bugmail puremagic.com (23/23) Mar 29 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12489
- d-bugmail puremagic.com (12/23) Mar 29 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12489
- d-bugmail puremagic.com (12/14) Mar 30 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12489
- d-bugmail puremagic.com (21/27) Mar 30 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12489
https://d.puremagic.com/issues/show_bug.cgi?id=12489 Summary: std.bitmanip byte swapping routines should be partially instantiable Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: andrej.mitrovich gmail.com 12:15:14 CET --- I've had a use case for generic endianness swapping when reading file headers, and was going to use attributes. For example: struct Header { Converter!(littleEndianToNative!ushort) ushort reserved1; } Unfortunately this doesn't work because you can't partially instantiate littleEndianToNative: Error: template instance littleEndianToNative!ushort does not match template declaration littleEndianToNative(T, uint n)(ubyte[n] val) if (canSwapEndianness!T && n == T.sizeof) It would have to be converted to a template, e.g.: Before: ----- T littleEndianToNative(T, size_t n)(ubyte[n] val) safe pure nothrow ----- After: ----- template littleEndianToNative(T) { T littleEndianToNative(size_t n)(ubyte[n] val) safe pure nothrow { ... } } ----- -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 29 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12489 12:32:30 CET --- Here's a somewhat generic wrapper workaround: ----- template PartialTempl(alias templ, T...) { auto PartialTempl(Args...)(auto ref Args args) { return templ!T(args); } } ----- Usable as: ----- Converter!(PartialTempl!(littleEndianToNative, ushort)) ushort reserved1; ----- Of course 'littleEndianToNative' and friends take a ubyte[N], not a ushort, so in my file loading routine I have to take that into account. But using attributes is pretty nice. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 29 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12489 Andrej Mitrovic <andrej.mitrovich gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WONTFIX 21:01:05 CET ---Here's a somewhat generic wrapper workaround: ----- template PartialTempl(alias templ, T...) { auto PartialTempl(Args...)(auto ref Args args) { return templ!T(args); } } -----This solves it for me. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 29 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12489 Vladimir Panteleev <thecybershadow gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |thecybershadow gmail.com 14:37:22 EEST ---Converter!(littleEndianToNative!ushort) ushort reserved1;I don't know the context, but there's some redundancy here already (ushort is listed twice). Any reason you can't use ` Converter!littleEndianToNative` ? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 30 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12489 14:45:56 CEST ---Yeah you're right, I don't need to embed this information. It's really nice that I can now write: struct Header { Converter!littleEndianToNative { ushort reserved1; ushort ordnum; ushort insnum; ushort patnum; ushort flags; ushort cwtv; ushort version_; } } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------Converter!(littleEndianToNative!ushort) ushort reserved1;I don't know the context, but there's some redundancy here already (ushort is listed twice). Any reason you can't use ` Converter!littleEndianToNative` ?
Mar 30 2014