[Issue 12489] New: std.bitmanip byte swapping routines should be partially instantiable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 29 04:15:16 PDT 2014
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 at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2014-03-29 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: -------
More information about the Digitalmars-d-bugs
mailing list