Manipulating Bits of Any Value Type
"Nordlöw"
per.nordlow at gmail.com
Sun Jan 26 15:37:39 PST 2014
On Sunday, 26 January 2014 at 23:27:58 UTC, Stanislav Blinov
wrote:
> On Sunday, 26 January 2014 at 20:56:29 UTC, Nordlöw wrote:
>
>> My idea to make `getBit` work on all types that have value
>> semantics.
>
> All of them? Arbitrary structs too? floating point types?
> Static arrays? Might I ask... why do you need this sort of
> thing? :)
For bit-parallel run-length encoding for efficient serialization
of sets of std.datetime:SysTime structures (16 bytes). I'm trying
to differentially pack sets of SysTimes entries more efficiently
because for a given directory containing files many of these
files often share the majority of their bits. Meta-code:
foreach (n; 0..SysTime.sizeof)
RLC all n-bits for all SysTimes
It is more an interesting experiment :)
>> That's why I need the cast (I think). Is there a traits to
>> check if a type has value semantics or not?
>
> The closest would be std.traits.hasIndirections.
Does this work recursively on containing types?
>> Also is there a trait to check if a type supports a specific
>> operation such as bitwise and `&`? I could always use
>> `__traits(compiles, ...)` but standardization is good.
>
> No there isn't.
Thx.
More information about the Digitalmars-d-learn
mailing list