Can I create a package with friendly modules

Mike Parker aldacron at gmail.com
Sun Jun 12 05:46:17 UTC 2022


On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote:
> Is it possible to create a package.d, consisting of (for 
> example), two modules, where each module can access private 
> declarations within each other.
>
> In essence, declaring 'a module level friendship', or a kind of 
> 'extended module' if you want.
>
> I might still want to add another module to the package, that 
> is NOT part of that friendship between those other two modules, 
> but is otherwise related to the solution.

- packagename
-- package.d
-- futuremodule.d
--- subpackagename
---- friend1.d
---- friend2.d

```
// friend1.d
module packagename.subpackagename.friend1;

package void doSomethingFriendly();

///////
// friend2.d
module packagename.subpackagename.friend2;

import packagename.subpackagename.friend1;

void doSomething() { doSomethingFriendly(); }

///////
// package.d
module packagename;

public import
     packagename.subpackagename.friend1,
     packagename.subpackagename.friend2,
     packagename.futuremodule;
```


More information about the Digitalmars-d-learn mailing list