Pop quiz, what does this do?

Stefan Koch uplink.coder at googlemail.com
Wed Mar 3 18:02:01 UTC 2021


On Wednesday, 3 March 2021 at 17:17:52 UTC, Simen Kjærås wrote:
> On Wednesday, 3 March 2021 at 16:33:35 UTC, Stefan Koch wrote:
>> On Wednesday, 3 March 2021 at 16:31:53 UTC, Stefan Koch wrote:
>>> On Wednesday, 3 March 2021 at 16:06:48 UTC, Steven 
>>> Schveighoffer wrote:
>>>> The FieldNameTuple from std.traits returns a tuple of names 
>>>> of all the fields that are present on a type instance.
>>>>
>>>> What about the result on things that can't have fields?
>>>>
>>>> import std.traits;
>>>>
>>>> interface I
>>>> {
>>>>    int foo();
>>>> }
>>>>
>>>> pragma(msg, FieldNameTuple!I);
>>>>
>>>> Without looking up the docs, or trying it, what do you think 
>>>> it does?
>>>>
>>>> -Steve
>>>
>>> My feeling is that it returns tuple("foo").
>>> But based on the name that probably shouldn't happen.
>>
>> Huh ... it works as it should in this case.
>> Pleasant surprise :)
>
> No it doesn't. Look again.
>
> --
>   Simen

:p I actually expected tuple("") :)
Don't ask me why.

Of course when trying to the result for anything that's bogus.
But using phobos introspection templates always leads to pain, so 
it's a good thing to teach people not to do that :)


More information about the Digitalmars-d mailing list