My two cents

Walter Bright newshound2 at digitalmars.com
Mon Oct 23 20:47:26 UTC 2017


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());

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