Flag proposal

so so at so.so
Sun Jun 12 05:58:10 PDT 2011


On Sun, 12 Jun 2011 15:33:00 +0300, Daniel Murphy  
<yebblies at nospamgmail.com> wrote:

> "Timon Gehr" <timon.gehr at gmx.ch> wrote in message
> news:it0oee$ehu$1 at digitalmars.com...
>>
>> What about allowing anonymous enums in parameter lists? Unfortunately  
>> that
>> would
>> be a language feature. :)
>>
>> T someAlgorithm(..., enum {unsorted, sorted} sortOutput);
>>
>> To call: someAlgorithm(..., sorted); / someAlgorithm(..., unsorted);
>>
>
> Wow - I actually really like this!  It would provide an even _better_
> solution than named arguments for this type of thing!
>
> The best part is that it could degrade to the enum's base type when  
> taking a
> function pointer, mangling the function's name and even inside the
> function's body!
>
> void myfunction(enum : int { option1, option2, option3 } options)
> {
>     static assert(is(typeof(options) == int));
> }
> static assert(is(typeof(&myfunction) == void function(int));
>
> myfunction(option2);

This also means you can use it only once. Not knowing the type, you can't  
pass as a variable either.
The loss is too big compared to the gain.

fun_step_one(enum whatever)
fun_step_two(enum?)

enum type? val
fun(val)


More information about the Digitalmars-d mailing list