On Monday, 9 May 2016 at 12:36:00 UTC, Ali Çehreli wrote:
On 05/09/2016 03:44 AM, Dicebot wrote:

> Ali version generates a compile-time switch for index

I think it's a run-time switch, generated by a compile-time foreach:

E front() {
    final switch (index) {                    // <-- RUNTIME
/* static */ foreach (i, arg; Args) { // <-- COMPILE TIME
            case i:                           // <-- RUNTIME
                return arg;                   // <-- RUNTIME
        }
    }
}

Quite confusing. :)

It becomes even more confusing if you keep in mind that it is a final switch on an index range known at compile-time - which means that as long as whole template can be inlined and actual index is know at CT, compiler can eliminate all runtime indexing checks and just replace it with matching literal/symbol.


Reply via email to