Is this possible in D?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 19 02:05:39 PST 2015


On Thursday, 19 February 2015 at 09:38:48 UTC, Mike Parker wrote:
> On Thursday, 19 February 2015 at 08:24:08 UTC, 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 should be able to cobble something together with string 
> mixins.

I'm still holding out hope for some sort of .codeof


More information about the Digitalmars-d-learn mailing list