Pop quiz, what does this do?

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Mar 3 17:35:30 UTC 2021


On Wed, Mar 03, 2021 at 11:06:48AM -0500, Steven Schveighoffer via Digitalmars-d 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?
[...]

My guess was it should be an empty tuple.

Boy was I surprised. :-(

I dug through the git history and found the original PR:

	https://github.com/dlang/phobos/pull/2561

Somebody asked why an empty string instead of an empty tuple, and the
submitter said he would change it, but then someone else said to keep
consistency, and apparently it was subsequently overlooked or just left
at an empty string.

My gut feeling is, this should be changed to an empty tuple. It really
makes no sense otherwise, and is a strange corner case like the kind
deadalnix mentioned that will lead to pain down the road.


T

-- 
A mathematician is a device for turning coffee into theorems. -- P. Erdos


More information about the Digitalmars-d mailing list