@disable this for structs

Dicebot public at dicebot.lv
Fri Feb 28 06:37:36 PST 2014


On Friday, 28 February 2014 at 13:42:21 UTC, Mike Parker wrote:
> Consider this.
>
> enum Foo {...}
>
> interface Bar {}
>
> struct BarManager {
>    public static {
>       void initialize();
>       void terminate();
>       ... more stuff
>    }
> }
>
> This is my use-case. I don't want my users to have to refer to 
> Foo or Bar with any sort of prefix except to avoid 
> name-clashes. However, I want to logically group the functions 
> to manage Bars under a single grouping. I don't need or want a 
> Singleton for it. I could use free functions, but I use the 
> initialize/terminate idiom a lot. As a user of my own library, 
> it would be horribly annoying to have to fully qualify each 
> call. Plus, now and again I have multiple "namespace structs" 
> in a single module. If I see them as all being closely related, 
> why should I split them off into different modules?

I'd write it this way:

=== something/bar.d ===

interface Bar {}

=== something/barmanager.d ===

import something.bar; // possibly public import

void initialize();
void terminate();

=== app.d ===

import something.bar;
import barmanager = something.barmanager;

// refer to Bar directly and to init function via 
barmanager.initialize()
=========

Or, even better, turn bar into package and have 
something.bar.manager with same usage pattern.


More information about the Digitalmars-d-learn mailing list