Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 23, 2012 [Issue 9065] New: Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9065 Summary: Please consider adding these std.traits Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: turkeyman@gmail.com --- Comment #0 from Manu <turkeyman@gmail.com> 2012-11-23 06:06:00 PST --- I'm constantly writing static logic code where I have no real idea what I'm really doing, and when I finally get it working, it's unreadable. This usually involves lots of careful is()-ing and __traits-ing. I'd really appreciate these templates added to std.traits: Tell me if T is a variable; ie, has a value, has an address (not an enum), ... template isVariable(alias T) { ... } Tell me if T is a function definition, not just if I can call it. I can easily find if something is a function pointer/delegate, or a method, or virtual, or abstract, or various other function related details, but surprisingly, not if T is just a function definition or not. template isFunctionDefinition(alias T) { ... } I want to know if I is an instance of some template T. template isInstanceOf(alias T, I) { ... } Perhaps like this: http://dpaste.dzfl.pl/fedac944 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-24 09:59:20 PST --- (In reply to comment #0) > template isInstanceOf(alias T, I) { ... } That one is now in Phobos: http://d.puremagic.com/issues/show_bug.cgi?id=9064 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #2 from Manu <turkeyman@gmail.com> 2012-11-24 10:59:39 PST --- (In reply to comment #1) > (In reply to comment #0) > > template isInstanceOf(alias T, I) { ... } > > That one is now in Phobos: http://d.puremagic.com/issues/show_bug.cgi?id=9064 Sweet. Any chance of the other 2? I'd really like to delete all my unreadable fail code asap. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 David Nadlinger <code@klickverbot.at> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |code@klickverbot.at --- Comment #3 from David Nadlinger <code@klickverbot.at> 2012-11-24 11:01:39 PST --- For the second point, what about is(T == function)? The is() syntax is not very popular (rightfully so), but I am not sure if we have a decision to replicate even its most basic use cases in std.traits yet. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #4 from Manu <turkeyman@gmail.com> 2012-11-24 11:48:53 PST --- (In reply to comment #3) > For the second point, what about is(T == function)? The is() syntax is not very > popular (rightfully so), but I am not sure if we have a decision to replicate > even its most basic use cases in std.traits yet. Does that not test if T is some sort of function pointer? ...actually, that's some sort of special case overloaded meaning of the function keyword in conjunction with 'is' isn't it? I think I remember running into that like, a year ago. I recall being very confused at the time. Will that only pass in function definitions? Will exclude function pointers? The first point is by far the most important, it's the one I really have no idea how to do properly myself. I have templates that kinda work, but seem to break in some cases, and I use it constantly. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #5 from David Nadlinger <code@klickverbot.at> 2012-11-24 11:51:44 PST --- (In reply to comment #4) > Does that not test if T is some sort of function pointer? > > ...actually, that's some sort of special case overloaded meaning of the > function keyword in conjunction with 'is' isn't it? I think I remember running > into that like, a year ago. I recall being very confused at the time. > Will that only pass in function definitions? Will exclude function pointers? Yes, this is one of the ugliest parts of the is() syntax. You are probably right, the fact alone that "function" has a different meaning here than in the rest of the language probably warrants inclusion of an isFunction() trait… -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 Jonathan M Davis <jmdavisProg@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg@gmx.com --- Comment #6 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-11-24 12:13:34 PST --- is(T == function) actually tests whether T is the type of a function, not whether it's a function pointer. This stackoverflow question discusses the differences between is(T == function), isFunctionPointer!T, isDelegate!T, and isSomeFunction!T: http://stackoverflow.com/questions/11067972/functions-versus-function-pointers-whats-the-difference A related issue is issue# 4427 We may want to add more of these to std.traits, but we should probably think carefully about exactly what we should add, especially because is expressions do most (all?) of it already, and often fairly cleanly. It's just that they're complicated enough in general and not understood well enough, that many people don't have a clue what they can do. It still may be worth adding stuff like isVariable to std.traits though. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #7 from Manu <turkeyman@gmail.com> 2012-11-24 14:35:53 PST --- (In reply to comment #6) > is(T == function) actually tests whether T is the type of a function, not whether it's a function pointer. This stackoverflow question discusses the differences between is(T == function), isFunctionPointer!T, isDelegate!T, and isSomeFunction!T: > > http://stackoverflow.com/questions/11067972/functions-versus-function-pointers-whats-the-difference Looking at that link, what's with all the typeof(bar) stuff? Do those tempaltes not work by alias? Surely I should be able to say isSomeFunction!bar, not requiring isSomeFunction!(typeof(bar)) ? Using typeof() like that makes generic code harder, because 'bar' could be anything, and if it doesn't have a typeof, then it is a different compile error and I have to produce even more logic prior to eliminate that case. Surely that could be encapsulated? > A related issue is issue# 4427 > > We may want to add more of these to std.traits, but we should probably think carefully about exactly what we should add, especially because is expressions do most (all?) of it already, and often fairly cleanly. It's just that they're complicated enough in general and not understood well enough, that many people don't have a clue what they can do. It still may be worth adding stuff like isVariable to std.traits though. In my experience, code to the effect of isVariable is actually rather non-trivial. It would be very useful. Ideally, written by someone who knows what they're doing ;) (I clearly don't) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 24, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #8 from Manu <turkeyman@gmail.com> 2012-11-24 14:41:05 PST --- > A related issue is issue# 4427 It's interesting to note that in your very first reply you were confused by is(T == function) too. I really think isFunction! should be added. It seems there is significant evidence to support it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 25, 2012 [Issue 9065] Please consider adding these std.traits | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | http://d.puremagic.com/issues/show_bug.cgi?id=9065 --- Comment #9 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-11-24 20:35:26 PST --- > Looking at that link, what's with all the typeof(bar) stuff? Do those > tempaltes not work by alias? Surely I should be able to say > isSomeFunction!bar, not requiring isSomeFunction!(typeof(bar)) ? std.traits operates on types, so I would not expect isSomeFunction!bar to ever work. You need to pass it a type. That's how everything in that module works. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation