private alias for module
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Tue Aug 14 06:38:56 PDT 2007
Myron Alexander wrote:
> Hello.
>
> I would like to declare an alias private to the module. As of D1.020,
> this is not the case and the specification seems to agree with the
> implementation.
>
> By private alias, I mean (eg):
>
>> ----- somemodule ----
>> module somemodule;
>> import std.string.toString;
>> private alias std.string.toString str;
>> ... code that uses str ...
>>
>> --- main ----
>> import somemodule;
>> void main () {
>> str (50); // should fail
>> }
>
> Is there a way to do this?
>
> At the moment, I understand my only options as:
>
> 1. Selective import with function rename
> 2. Create another module for the alias and import into "somemodule"
>
> Problem with option 1 is that I then have to declare each function I
> use. Problem with option 2 is that I have an additional file.
>
> If this is by design, then what is the reasoning behind forbidding
> private aliases?
>
> Thanks ahead,
>
> Myron Alexander.
I'm not sure what the reasoning is, and would just assume have private aliases as well.
But I can add another option. Assuming you just want std.string.* to have a shorter name,
you could try a static+renaming import.
static import str = std.string;
// ...
str.toString(50);
If its something else you're after... then I don't know.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list