PackedAliasSeq?
Simen Kjærås
simen.kjaras at gmail.com
Mon Feb 26 08:53:52 UTC 2018
On Thursday, 22 February 2018 at 19:26:54 UTC, Andrei
Alexandrescu wrote:
> template PackedAliasSeq!(T...)
> {
> alias expand = AliasSeq!T;
> }
I started playing around with this a few days ago, and came up
with another interesting abstraction - NamedPack:
alias foo = NamedPack!("Type", int, "name", "foo");
assert(is(foo.Type == int));
assert(foo.name == "foo");
assert(foo.equals!(NamedPack!("Type", int, "name", "foo")));
And for good measure, a helper to define your own 'compile-time
structs', for want of a better word:
alias Field = DefinePack!("Type", Type, "name", string,
"offset", int);
alias field1 = Field!(int, "a", 0);
assert(is(field1.Type == int));
assert(field1.name == "a");
assert(field1.offset == 0);
assert(field1.equals!(NamedPack!("Type", int, "name", "a",
"offset", 0)));
One benefit over regular structs being of course that these will
never end up in the binary.
The more structured nature of this construct over the simple Pack
template makes it useful where information would otherwise be
encoded in the order of elements, as e.g. in pull #6192.
Implementation and some more documentation:
https://gist.github.com/Biotronic/8a2664c050f01aed5e0c45950509022b
--
Simen
More information about the Digitalmars-d
mailing list