Build an AliasSeq from memberFunction return types
Timoses
timosesu at gmail.com
Fri Mar 9 17:47:46 UTC 2018
Hi,
I feel like starting to dig deeper into D. And I got lost : D.
I would like to reflect on defined bitfields:
struct S
{
mixin!(bitfields!(
<bitfieldType>, <bitfieldName>, <size>,
...
));
}
which produces something like this in the back scenes:
struct S
{
uint storage;
@property <bitfieldType> <bitfieldName>() {
... return field from storage;
}
}
There is an approach here:
https://forum.dlang.org/post/o5u21b$15f3$1@digitalmars.com
However, it feels a bit overcomplicating the issue perhaps.
To retrieve the member names the following (and filtering for
only the functions) does the job:
alias members = aliasSeqOf!([__traits(allMembers, S)]);
However, I now would want to build an AliasSeq of the types. My
idea would be (absolute pseudocode!!!):
alias memberTypes;
static foreach (member; members)
{
memberTypes ~= ReturnType!S.member;
}
pragma(msg, memberTypes); // prints sth like: (int, bool,
uint, ...)
I have taken a look at https://dlang.org/phobos/std_meta.html but
am unsure whether I can actually build an AliasSeq iteratively.
The mentioned example might help:
alias TL = AliasSeq!(int, double);
alias Types = AliasSeq!(TL, char);
static assert(is(Types == AliasSeq!(int, double, char)));
However, I can't simply do
static foreach (i, member; members)
{
alias memberTypes_i = AliasSeq!
(memberTypes_i, ReturnType!S.<member>) // <--- no idea
even how to get
// the ReturnType
here...
// S.member does
not work
}
alias memberTypes = AliasSeq!(memberTypes_i_max);
But what the heck! I can't find a solution!
This might be related to:
https://forum.dlang.org/post/pxtqeahzxrsrljnrworq@forum.dlang.org
Do you have any ideas? Or does your head start spinning like mine
does, too?
More information about the Digitalmars-d-learn
mailing list