On 1/20/16 4:44 PM, David Nadlinger wrote:
On Wednesday, 20 January 2016 at 21:27:15 UTC, Steven Schveighoffer wrote:
It would be cool if the compiler could "expand" a finitely
instantiable template (one with a finite number of ways it can be
instantiated) based on a runtime value, and do the switch for me.
Can't you just write a wrapper function that takes the template function
as a compile-time argument and generates the switch for you by iterating
over the std.traits.EnumMembers of said compile-time parameter?
I'm sure it can be done using some existing techniques, possibly with
mixins.
However, one thing I didn't mention is the function called foo would
likely simply be inline code in the higher level function, if it could be.
Imagine if you such a call returned something, and you simply used it
throughout the rest of your function. The compiler could rewrite this as
a template and compile all three versions and branch to the appropriate
one, but your code would simply read as a straightforward procedural
function.
In any case, it was an idea that I had, not sure if it makes a lot of
sense. It would likely be a huge amount of work on the compiler.
-Steve