alias this on module

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Mon May 1 14:50:02 PDT 2017


On Monday, 1 May 2017 at 12:41:19 UTC, Steven Schveighoffer wrote:
> On 4/30/17 7:59 PM, Jonathan Marler wrote:
>> On Sunday, 30 April 2017 at 23:44:32 UTC, Steven Schveighoffer 
>> wrote:
>>> On 4/30/17 7:35 PM, Jonathan Marler wrote:
>>>> Any reason why "alias this" doesn't work at the module 
>>>> level?  If I
>>>> recall correctly, a module is really just a "class" under 
>>>> the hood, but
>>>> when I tried to use it I got:
>>>>
>>>> Error: alias this can only be a member of aggregate, not 
>>>> module
>>>> <module-name>
>>>>
>>>
>>> public import is to modules as alias this is to 
>>> structs/classes :)
>>>
>>
>> They're actually different.
>>
>> //
>> // File: mymodule.d
>> //
>> module mymodule;
>>
>> struct Foo
>> {
>>     int bar;
>>     void baz();
>> }
>> __gshared Foo foo;
>> alias foo this; // using "alias this" on a module
>
> So you want to alias a struct to a module? That's different 
> than what I thought, I thought you wanted to alias one module's 
> members into another.
>
> I can't see a reason why it couldn't be added as a feature. I 
> admit I'm not seeing the benefit though.
>
> You could simulate this via a mixin. e.g.:
>
> void baz()
> {
>    foo.baz;
> }
>
> @property ref bar()
> {
>    return foo.bar;
> }
>
> -Steve

Ya now you get it. It's not a big deal, it's just that after I 
thought about it, I couldn't think of a reason why it's not 
supported.  I actually have an application for it too.  Since 
modules are just classes under the hood, I was wondering if 
implementing it would be as simple as commenting out an error 
message like Andre's [nested import 
example](https://www.youtube.com/watch?v=3NihZVcZqto&t=183s&#t=27m15s)


More information about the Digitalmars-d mailing list