As the unit of encapsulation is the module, it sometimes makes sense to manage construction of a certain type on a by-module basis instead of a by-type basis.
Therefore, the following code should compile:
struct S{
private this();
private init;
// (probably we also want @disable init, instead of
// needing to hack around lack of it by hiding it
// with a new declaration.)
}
Within the module, S should be default-constructible and S.init should be accessible, but not outside the module.
This gives the author of the type full control over how S is constructed, but it does not unduly constrain the author.
package and protected default construction are analogous. Probably, explicit 'public' should be allowed as well.
Comment #1 by robert.schadek — 2024-12-13T18:45:13Z