Idea: limited template expansion

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 21 05:37:47 PST 2016


On 1/21/16 7:18 AM, Sebastiaan Koppe wrote:
> On Wednesday, 20 January 2016 at 21:44:06 UTC, David Nadlinger wrote:
>> 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>))`.
>
> I have used EnumMembers a few times and it definitely saved me the
> hassle of writing the switch myself.
>
> However, in this case, isn't there a mapping between enums and types
> that one still needs to specify? That is: ( UTF8=>char[],
> UTF16=>wchar[], UTF32=>dchar[] ).

Yeah, you really need an enum to make this make sense (there's not a 
great way to tell the compiler "I only mean char types"). I didn't show 
what it would look like, but one is trivial to write.

-Steve


More information about the Digitalmars-d mailing list