Iterate over symbols in tupleof without instance
Benjamin Thaut
code at benjamin-thaut.de
Tue Apr 15 05:30:43 PDT 2014
Am 15.04.2014 13:25, schrieb Artur Skawina:
> On 04/15/14 12:45, Dicebot wrote:
>> void iterate(T)()
>> {
>> foreach (index, member; T.init.tupleof)
>> {
>> pragma(msg, __traits(identifier, T.tupleof[index]));
>> }
>> }
>>
>> struct A
>> {
>> int a, b, c;
>> }
>>
>> void main()
>> {
>> iterate!A();
>> }
>>
>> Reason why you can't naively iterate over T.tupleof is that current tuple foreach tries to look like normal foreach and thus iteration parameters can't be types.
>
> void iterate(T)()
> {
> foreach (index, member; typeof(T.tupleof))
> {
> pragma(msg, __traits(identifier, T.tupleof[index]));
> }
> }
>
> artur
>
I want to iterate over the symbols, not over the types that the symbols
have. I need to iterate over the symbols, because UDAs are attached to
the symbols. Because of that none of the here listed solutions work for me.
Here is a small example of what I'm trying to do:
http://dpaste.dzfl.pl/4645d6537447
And no, I can not use __traits(allMembers, T) and __traits(getMember, T,
m) because some time ago __traits(getMember, ...) was changed so it can
no longer access protected members. (obviously it will work if the type
that should be iterated over is within the same module, but thats not
the case in practice.)
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d-learn
mailing list