Is this possible in D?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 19 08:15:34 PST 2015


On Thu, 19 Feb 2015 08:24:06 +0000, Jonathan Marler wrote:

> I am having a heck of a time trying to figure out how to do this.
>   How do I change the attributes of a function based on the
> version without copying the function body?  For example:
> 
> version(StaticVersion) {
>      static void myLongFunction()
>      {
>          // long body ...
>      }
> } else {
>      void myLongFunction()
>      {
>          // same long body copied...
>      }
> }
> 
> In one version I want the function to be static and in another I don't
> want it to be static.  I cannot figure out how to do this without
> copy/pasting the entire function body to both versions.

you can turn `myLongFunction()` to a template `myLongFunctionImlp()()`, 
and then simply declare `myLongFunction()` with required attributes, 
simply instantiating template in it's body.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150219/4203f8bf/attachment.sig>


More information about the Digitalmars-d-learn mailing list