Enum of functions?

Chris Williams yoreanon-chrisw at yahoo.co.jp
Mon Nov 25 21:51:56 PST 2013


On Tuesday, 26 November 2013 at 05:13:00 UTC, Shammah Chancellor 
wrote:
> What is the practical purpose of such a thing?
>
> -Shammah

The two cases I can think of are:

1. To define a set of supported handlers which can be passed in 
as a parameter to a call. Rather than writing a switch in your 
method that calls the correct function, based on the supported 
values in the enum, you build the handlers right into the enum. 
It pulls your code into one.

2. If you have a quick and easy method for serializing an enum - 
for example, converting the name to a string and back - then you 
can write can write code that deserializes and calls a function 
in a single line.

But mostly, I was just curious.


More information about the Digitalmars-d-learn mailing list