Inconsistency between `AllMembers` and `hasMember`

bauss jj_1337 at live.dk
Sun Nov 18 09:10:57 UTC 2018


On Sunday, 18 November 2018 at 02:37:13 UTC, Stanislav Blinov 
wrote:
> On Sunday, 18 November 2018 at 00:51:51 UTC, drug wrote:
>> On 18.11.2018 1:26, Adam D. Ruppe wrote:
>>> 
>>> That's because the compiler passes it a hidden pointer to 
>>> refer to the context outside. The compiler could perhaps be 
>>> smarter about it, and see if those methods actually refer to 
>>> the context, but it seems to simply say if the method is 
>>> there, it might refer to it and it adds the context pointer 
>>> (note that S.sizeof increases too) and a magic constructor to 
>>> set it.
>> Well, if "this" means hidden pointer then it never should be 
>> returned by AllMembers at all, isn't it?
>
> It's only "hidden" in that there's no symbol to access it. But 
> you can still access it via .tupleof, and it still of course 
> affects the ABI (i.e. S.sizeof is always at least pointer size 
> when S is nested).
> If you want to iterate fields, .tupleof is a better way to do 
> it. As for that hidden pointer, you can just test with 
> __traits(isNested, S) whether that's present, and just don't 
> look at the last field.

But in that case shouldn't you be able to tell whether it has it 
or not through hasMember?


More information about the Digitalmars-d-learn mailing list