Idea: limited template expansion

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 13:44:06 PST 2016


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?

Something like `enumTemplateDispatch!foo(detectBOM(buffer), 
<runtime args>))`.

Depending on what template signatures you want to support, you 
might need to make enumTemplateDispatch explicitly take the enum 
type to use or the position of the respective parameter in the 
template argument list of the target.

  — David


More information about the Digitalmars-d mailing list