My two cents

Rainer Schuetze r.sagitario at gmx.de
Tue Oct 24 20:54:27 UTC 2017



On 23.10.2017 22:47, Walter Bright wrote:
> On 10/18/2017 1:56 AM, Satoshi wrote:
>> Unable to publish closed source library without workaround and ugly 
>> PIMPL design.
> 
> 
> Consider this:
> 
> ----------- file s.d ------------
>    struct S {
>      int x;
>      this(int x) { this.x = x; }
>      int getX() { return x; }
>    }
> ----------- file s.di ------------
>    struct S {
>      this(int x);
>      int getX();
>    }
> --------------------------
> 
> User code:
> 
>      import s;
>      S s = S(3);
>      writeln(s.getX());

I doubt this reserves enough space on the stack for the copy.

> 
> Ta dah! Implementation is hidden, no PIMPL. Of course, inlining of the 
> member functions won't work, but it won't work in C++, either, when this 
> technique is used.
> 
> I.e. you can use .di/.d files just like you'd use .h/.cpp in C++. The 
> technique works with classes, too.


More information about the Digitalmars-d mailing list