digitalmars.D - Pop quiz, what does this do?
- Steven Schveighoffer (11/11) Mar 03 2021 The FieldNameTuple from std.traits returns a tuple of names of all the
- Stefan Koch (4/16) Mar 03 2021 My feeling is that it returns tuple("foo").
- Stefan Koch (3/25) Mar 03 2021 Huh ... it works as it should in this case.
- Steven Schveighoffer (8/32) Mar 03 2021 It works as designed. It's the design I question.
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (4/30) Mar 03 2021 No it doesn't. Look again.
- Stefan Koch (6/37) Mar 03 2021 :p I actually expected tuple("") :)
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (9/20) Mar 03 2021 I remember seeing that a couple years back
- Steven Schveighoffer (5/27) Mar 03 2021 Oh snap! almost 2 years ago, I had the same exact WTF moment.
- Max Haughton (3/15) Mar 03 2021 "" - difference between a field and a member I'm guessing
- Steven Schveighoffer (10/30) Mar 03 2021 No, it's not. A member that's not a field doesn't normally produce
- Dukc (5/13) Mar 03 2021 I'd think it either returns nothing, or the typeid and monitor
- Steven Schveighoffer (3/18) Mar 03 2021 It does neither of those things.
- H. S. Teoh (16/31) Mar 03 2021 [...]
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
Mar 03 2021
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? -SteveMy feeling is that it returns tuple("foo"). But based on the name that probably shouldn't happen.
Mar 03 2021
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:Huh ... it works as it should in this case. Pleasant surprise :)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? -SteveMy feeling is that it returns tuple("foo"). But based on the name that probably shouldn't happen.
Mar 03 2021
On 3/3/21 11:33 AM, Stefan Koch wrote:On Wednesday, 3 March 2021 at 16:31:53 UTC, Stefan Koch wrote:It works as designed. It's the design I question. For instance, code like: foreach(m; FieldNameTuple!T) // do something with __traits(getMember, T, m) will fail. Not because FieldNameTuple complains that it can't have field names, but because of what it's hard-coded to do. -SteveOn Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:Huh ... it works as it should in this case. Pleasant surprise :)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 feeling is that it returns tuple("foo"). But based on the name that probably shouldn't happen.
Mar 03 2021
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:No it doesn't. Look again. -- SimenOn Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:Huh ... it works as it should in this case. Pleasant surprise :)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? -SteveMy feeling is that it returns tuple("foo"). But based on the name that probably shouldn't happen.
Mar 03 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::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 :)On Wednesday, 3 March 2021 at 16:31:53 UTC, Stefan Koch wrote:No it doesn't. Look again. -- SimenOn Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:Huh ... it works as it should in this case. Pleasant surprise :)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? -SteveMy feeling is that it returns tuple("foo"). But based on the name that probably shouldn't happen.
Mar 03 2021
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?I remember seeing that a couple years back (https://forum.dlang.org/post/hwrsxypruzeffreqxasa forum.dlang.org). It seems intentional, but also very, very weird. Accordion to the PR (https://github.com/dlang/phobos/pull/2561), it was for consistency. Consistency with what, however, is unclear. -- Simen
Mar 03 2021
On 3/3/21 11:41 AM, Simen Kjærås wrote:On Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:Oh snap! almost 2 years ago, I had the same exact WTF moment. Except this time, it is affecting code that I have to fix.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?I remember seeing that a couple years back (https://forum.dlang.org/post/hwrsxypruzeffreqxasa forum.dlang.org). It seems intentional, but also very, very weird.Accordion to the PR (https://github.com/dlang/phobos/pull/2561), it was for consistency. Consistency with what, however, is unclear.Thanks for the link. I think it's consistently uninutitive... -Steve
Mar 03 2021
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"" - difference between a field and a member I'm guessing
Mar 03 2021
On 3/3/21 11:42 AM, Max Haughton wrote:On Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:No, it's not. A member that's not a field doesn't normally produce anything in the tuple. Try this one: interface I { int foo(); int bar(); } -SteveThe 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"" - difference between a field and a member I'm guessing
Mar 03 2021
On Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote: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?I'd think it either returns nothing, or the typeid and monitor fields (or whatever they are) that all classes are supposed to have.
Mar 03 2021
On 3/3/21 11:52 AM, Dukc wrote:On Wednesday, 3 March 2021 at 16:06:48 UTC, Steven Schveighoffer wrote:It does neither of those things. -Steveimport std.traits; interface I { int foo(); } pragma(msg, FieldNameTuple!I); Without looking up the docs, or trying it, what do you think it does?I'd think it either returns nothing, or the typeid and monitor fields (or whatever they are) that all classes are supposed to have.
Mar 03 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
Mar 03 2021