Re: Shouldn't __traits return Tuples?

2009-04-03 Thread Gide Nwawudu
On Thu, 02 Apr 2009 03:56:35 +0200, Trass3r wrote: >I came across another strange bug(?): >Using const, static const or auto instead of enum makes it work. >Using the foreach way also works with enum. > >void main() >{ > enum members = ["foo", "bar"]; > for (uint i=0; i// foreach

Re: Shouldn't __traits return Tuples?

2009-04-02 Thread Max Samukha
On Thu, 02 Apr 2009 00:07:56 +0200, Trass3r wrote: >Max Samukha schrieb: >> On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r wrote: >> >>> OMG, I knew the recursion base case was missing, but I couldn't imagine >>> how to represent "nothing". Of course, an empty tuple. >>> >>> But the reason I post

Re: Shouldn't __traits return Tuples?

2009-04-02 Thread Don
Trass3r wrote: I came across another strange bug(?): Using const, static const or auto instead of enum makes it work. Using the foreach way also works with enum. void main() { enum members = ["foo", "bar"]; for (uint i=0; istd.encoding.EncodingSchemeASCIIà‘B ANSI_X3.4-1968 

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Daniel Keep
Trass3r wrote: > I came across another strange bug(?): > Using const, static const or auto instead of enum makes it work. > Using the foreach way also works with enum. > > void main() > { > enum members = ["foo", "bar"]; > for (uint i=0; i //foreach (i; Sequence!(members.length)) >

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
I came across another strange bug(?): Using const, static const or auto instead of enum makes it work. Using the foreach way also works with enum. void main() { enum members = ["foo", "bar"]; for (uint i=0; istd.encoding.EncodingSchemeASCIIà‘B ANSI_X3.4-1968  ’B

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
Max Samukha schrieb: On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r wrote: OMG, I knew the recursion base case was missing, but I couldn't imagine how to represent "nothing". Of course, an empty tuple. But the reason I posted is cause that bug(?) is still present. dmd doesn't crash anymore, but

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Max Samukha
On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r wrote: > >OMG, I knew the recursion base case was missing, but I couldn't imagine >how to represent "nothing". Of course, an empty tuple. > >But the reason I posted is cause that bug(?) is still present. >dmd doesn't crash anymore, but using const stil

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
Max Samukha schrieb: On Wed, 01 Apr 2009 20:54:12 +0200, Trass3r wrote: template Sequence(size_t count, size_t index = 0) { static if (index < count) alias Tuple!(index, Sequence!(count, index + 1)) Sequence; } There was ellipsis to suggest that you should terminate the recursion pr

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Max Samukha
On Wed, 01 Apr 2009 20:54:12 +0200, Trass3r wrote: >template Sequence(size_t count, size_t index = 0) >{ >static if (index < count) > alias Tuple!(index, Sequence!(count, index + 1)) Sequence; >} There was ellipsis to suggest that you should terminate the recursion properly :) Sorry t

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
Trass3r schrieb: enum members = __traits(allMembers, Class); foreach (i; Sequence!(members.length)) { static if (isFunction!(Class, members[i])) { foreach (j; __traits(getVirtualFunctions, Class, members[i])) writefln(members[i], ": ", typei

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
Trass3r schrieb: foreach (member; __traits (allMembers, Class)) { foreach (overload; __traits (getVirtualFunctions, Class, member)) { // do stuff } } omg, those bugs are known for nearly 2 years now. http://d.puremagic.com/issues/show_bug.cgi?id=1386 http://d.puremagic.com/

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Don
Trass3r wrote: Don schrieb: That situation should be much better now that we have all of the source code. If something changes, it'll be really easy to find exactly what caused the change. Well, if dmd was available in a source control repository we could really easily track the changes. A

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Trass3r
Don schrieb: That situation should be much better now that we have all of the source code. If something changes, it'll be really easy to find exactly what caused the change. Well, if dmd was available in a source control repository we could really easily track the changes.

Re: Shouldn't __traits return Tuples?

2009-04-01 Thread Don
Christopher Wright wrote: Trass3r wrote: Christopher Wright schrieb: Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things! Though it would be even better to have the runtime equivalent. Any chance traits get fixed anytime soon? I wa

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Christopher Wright
Trass3r wrote: Christopher Wright schrieb: Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things! Though it would be even better to have the runtime equivalent. Any chance traits get fixed anytime soon? I was using __traits + CTFE aro

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Trass3r
Christopher Wright schrieb: Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things! Though it would be even better to have the runtime equivalent. Any chance traits get fixed anytime soon?

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Christopher Wright
Trass3r wrote: Yeah extreeemely buggy. dmd also crashes if that enum members is changed to const members or invariant members. Buggy __traits is the major reason I'm not on d2. If __traits were not buggy, I could do, god, so many things! Though it would be even better to have the runtime equ

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Max Samukha
On Tue, 31 Mar 2009 13:53:02 +0200, Trass3r wrote: >Max Samukha schrieb: >>> So it is a tuple although the docs tell us it's an array? >>> >> >> Yeah, __traits returns expressions of various types depending on the >> Id. In case of getVirtualFunctions, it's a tuple expression. You may >> want to

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Trass3r
Max Samukha schrieb: "variable main.main.i voids have no value" __traits is buggy. template isFunction(C, string member) { enum isFunction = is(typeof(mixin("C." ~ member)) == function); } void main() { //SpinLock lock; enum members = __traits(allMembers, Class); foreach (i;

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Trass3r
Max Samukha schrieb: So it is a tuple although the docs tell us it's an array? Yeah, __traits returns expressions of various types depending on the Id. In case of getVirtualFunctions, it's a tuple expression. You may want to look through traits.c in dmd sources to see what's going on. So th

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Max Samukha
On Tue, 31 Mar 2009 10:55:22 +0200, Max Samukha wrote: >On Mon, 30 Mar 2009 22:04:57 +0200, Trass3r wrote: > >>Max Samukha schrieb: >>> It's possible to statically unroll the foreach's with a template >>> generating a tuple of consequtive integers (not tested): >>> >>> template Sequence(size_t

Re: Shouldn't __traits return Tuples?

2009-03-31 Thread Max Samukha
On Mon, 30 Mar 2009 22:04:57 +0200, Trass3r wrote: >Max Samukha schrieb: >> It's possible to statically unroll the foreach's with a template >> generating a tuple of consequtive integers (not tested): >> >> template Sequence(size_t count, size_t index = 0) >> { >>static if (index < count) >>

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Trass3r
Max Samukha schrieb: It's possible to statically unroll the foreach's with a template generating a tuple of consequtive integers (not tested): template Sequence(size_t count, size_t index = 0) { static if (index < count) alias Tuple!(index, Sequence!(count, index + 1)) Sequence; ..

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Tomas Lindquist Olsen
On Mon, Mar 30, 2009 at 5:13 PM, Tomas Lindquist Olsen wrote: > On Mon, Mar 30, 2009 at 5:11 PM, Jarrett Billingsley > wrote: >> On Mon, Mar 30, 2009 at 10:57 AM, Max Samukha >> wrote: Also the following doesn't work with dmd, returns 0 for all members: Base base = new Base; aut

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Jarrett Billingsley
On Mon, Mar 30, 2009 at 11:13 AM, Tomas Lindquist Olsen wrote: >>> getMembers has not been implemented, AFAIK >> >> It has in LDC ;) >> > > I think we need D2 support first ;) I was talking about the RTTI getMembers function :)

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Tomas Lindquist Olsen
On Mon, Mar 30, 2009 at 5:11 PM, Jarrett Billingsley wrote: > On Mon, Mar 30, 2009 at 10:57 AM, Max Samukha > wrote: >>>Also the following doesn't work with dmd, returns 0 for all members: >>> >>>Base base = new Base; >>>auto members = __traits(allMembers, typeof(base)); >>>foreach(m; members) >>

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Jarrett Billingsley
On Mon, Mar 30, 2009 at 10:57 AM, Max Samukha wrote: >>Also the following doesn't work with dmd, returns 0 for all members: >> >>Base base = new Base; >>auto members = __traits(allMembers, typeof(base)); >>foreach(m; members) >>     writefln(base.classinfo.getMembers(m).length); > > getMembers has

Re: Shouldn't __traits return Tuples?

2009-03-30 Thread Max Samukha
On Mon, 30 Mar 2009 15:06:09 +0200, Trass3r wrote: >Shouldn't __traits return Tuples instead of arrays (esp. allMembers) to >allow sophisticated compile time reflection? >Currently it seems impossible to do something along the lines of > >foreach (member; __trait

Shouldn't __traits return Tuples?

2009-03-30 Thread Trass3r
Shouldn't __traits return Tuples instead of arrays (esp. allMembers) to allow sophisticated compile time reflection? Currently it seems impossible to do something along the lines of foreach (member; __traits (allMembers, Class)) { foreach (overload; __traits (getVirtualFunctions,