Quick help on version function parameter

Jonathan Marler via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 18 15:21:43 PST 2015


Does anyone know a good way to support versioned function 
parameters?  Say, in one version I want a variable to be a global 
and in another I want it to be a parameter.

version(GlobalVersion)
{
     int x;
     void foo()
     {
         // A huge function that uses x
     }
} else {
     void foo(int x)
     {
         // A huge function that uses x (same code as 
GlobalVersion)
     }
}

The problem with this is that the code is duplicated.  Is there a 
way to do this versioning without having 2 copies of the same 
function body?  The following definitely does not work:

version(GlobalVersion)
{
     int x;
     void foo()
} else {
     void foo(int x)
}
     {
         // A huge function that uses x
     }


More information about the Digitalmars-d-learn mailing list