digitalmars.D - static foreach
- John S. Skogtvedt (14/14) Nov 15 2006 A kind of "static foreach" already works for tuples,
- Max Samuha (7/7) Nov 15 2006 On Wed, 15 Nov 2006 11:05:02 +0100, "John S. Skogtvedt"
- Reiner Pope (5/13) Nov 15 2006 The important difference between 'static if' and 'if' is that 'static
- Max Samuha (3/16) Nov 16 2006 Thanks for the explanation. I need to dig deeper into the specs.
A kind of "static foreach" already works for tuples, why not other constants as well? Example: import std.typetuple; void main() { alias TypeTuple!(void, void, void) TL; foreach (t; TL) { pragma(msg, "this prints three times"); } const char[] s = "abc"; foreach (c; s) { pragma(msg, "and maybe this should as well?"); } }
Nov 15 2006
On Wed, 15 Nov 2006 11:05:02 +0100, "John S. Skogtvedt" <jss2k2 chello.no> wrote: Why 'foreach' and not 'static foreach' is used for compile time iteration unlike 'static if' for compile time condition evaluation? Or is 'static' necessary in 'static if' at all? Can't the compiler determine whether 'if' is static based on the compile time evaluability of the expression?
Nov 15 2006
Max Samuha wrote:On Wed, 15 Nov 2006 11:05:02 +0100, "John S. Skogtvedt" <jss2k2 chello.no> wrote: Why 'foreach' and not 'static foreach' is used for compile time iteration unlike 'static if' for compile time condition evaluation? Or is 'static' necessary in 'static if' at all? Can't the compiler determine whether 'if' is static based on the compile time evaluability of the expression?The important difference between 'static if' and 'if' is that 'static if' doesn't create a new scope, whereas 'if' does. The compile-time vs runtime dichotomy is just a consequence of that; deferring handling of different scopes to runtime is just too complex.
Nov 15 2006
On Thu, 16 Nov 2006 09:50:35 +1100, Reiner Pope <reiner.pope REMOVE.THIS.gmail.com> wrote:Max Samuha wrote:Thanks for the explanation. I need to dig deeper into the specs.On Wed, 15 Nov 2006 11:05:02 +0100, "John S. Skogtvedt" <jss2k2 chello.no> wrote: Why 'foreach' and not 'static foreach' is used for compile time iteration unlike 'static if' for compile time condition evaluation? Or is 'static' necessary in 'static if' at all? Can't the compiler determine whether 'if' is static based on the compile time evaluability of the expression?The important difference between 'static if' and 'if' is that 'static if' doesn't create a new scope, whereas 'if' does. The compile-time vs runtime dichotomy is just a consequence of that; deferring handling of different scopes to runtime is just too complex.
Nov 16 2006