Re: A possible suggestion for the Foreach loop

2013-08-22 Thread Timon Gehr
On 08/21/2013 07:45 PM, Andrei Alexandrescu wrote: On 8/21/13 4:52 AM, John Colvin wrote: On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function

Re: A possible suggestion for the Foreach loop

2013-08-22 Thread Timon Gehr
On 08/21/2013 09:17 PM, Dicebot wrote: They are orthogonal and not exclusive. declaration foreach can appear whenever declaration can appear and insert new declarations, contrary to statements of normal foreach. static foreach is simply an improvement over existing tuple foreach concept which

Re: A possible suggestion for the Foreach loop

2013-08-22 Thread Timon Gehr
On 08/21/2013 10:53 PM, Dylan Knutson wrote: I do like the idea of it being called 'static foreach' instead of 'foreach', to keep in step with how the rest of the language handles other compile time constructs (static assert). Plus, as you said in your bugreport, visual disambiguation between

Re: A possible suggestion for the Foreach loop

2013-08-22 Thread Timon Gehr
On 08/22/2013 02:56 PM, Timon Gehr wrote: AFAIK one reason why it hasn't made it in yet were implementation issues related to DMD internals? The design was discussed in 2007's dconf IIRC. fixed.

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Tommi
On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: [..] -- T foo(T)(ref T thing) { thing++; return thing * 2; } foreach(Type; TupleType!(int, long, uint)) { unittest {

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread monarch_dodra
On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this would allow for templating constants and unittests easier. Take, for

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Kiith-Sa
On Wednesday, 21 August 2013 at 10:40:10 UTC, monarch_dodra wrote: On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread John Colvin
On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I would *LOVE* to have this. however, once we go down that route, it would be

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread monarch_dodra
On Wednesday, 21 August 2013 at 11:34:29 UTC, Kiith-Sa wrote: On Wednesday, 21 August 2013 at 10:40:10 UTC, monarch_dodra wrote: On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Dicebot
While you example can be re-written in a similar fashion with no major issues, it would have been a very useful tool to solve the problem with recursive template instantiation to embed declarations. Compare those two and count template instances: ---

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread bearophile
Dylan Knutson: I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this would allow for templating constants and unittests easier. See: http://d.puremagic.com/issues/show_bug.cgi?id=4085 Bye,

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Dicebot
On Wednesday, 21 August 2013 at 13:18:22 UTC, bearophile wrote: Dylan Knutson: I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this would allow for templating constants and unittests easier.

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread bearophile
Dicebot: They are orthogonal and not exclusive. declaration foreach can appear whenever declaration can appear and insert new declarations, contrary to statements of normal foreach. static foreach is simply an improvement over existing tuple foreach concept which allows it to work with a

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Dylan Knutson
On Wednesday, 21 August 2013 at 18:52:56 UTC, bearophile wrote: Dicebot: This bugzilla entry is on slightly related but different topic. declaration foreach != static foreach I think a well implemented static foreach is able to do anything a declaration foreach could do, and more. (If you

Re: A possible suggestion for the Foreach loop

2013-08-21 Thread Dylan Knutson
On Wednesday, 21 August 2013 at 10:02:33 UTC, Tommi wrote: Why not just do this: import std.typetuple; T foo(T)(ref T thing) { thing++; return thing * 2; } unittest { foreach(Type; TypeTuple!(int, long, uint)) { { Type tmp = 5; assert(foo(tmp) ==

A possible suggestion for the Foreach loop

2013-08-20 Thread Dylan Knutson
Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this would allow for templating constants and unittests easier. Take, for instance, this hypothetical example:

Re: A possible suggestion for the Foreach loop

2013-08-20 Thread Tyler Jameson Little
On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote: Hello, I'd like to open up discussion regarding allowing foreach loops which iterate over a tuple of types to exist outside of function bodies. I think this would allow for templating constants and unittests easier. Take, for