auto limitation?

bearophile bearophileHUGS at lycos.com
Tue Sep 11 14:55:40 PDT 2012


Namespace:

> But so far no suggestions?

This seems to work, but solutions that use cast() are sometimes 
fragile (and dangerous):


auto foo(bool b) {
     final switch (b) {
         case false:
             return 20.0;
         case true:
             return cast(typeof(return))10;
     }
}
void main() {
     import std.stdio: writeln;
     writeln(foo(false));
     writeln(foo(true));
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list