digitalmars.D.learn - private alias for module
- Myron Alexander (15/26) Aug 13 2007 Hello.
- Chris Nicholson-Sauls (9/45) Aug 14 2007 I'm not sure what the reasoning is, and would just assume have private a...
- Myron Alexander (7/19) Aug 14 2007 Chris,
- Extrawurst (4/23) Aug 14 2007 what abot that ?
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.
Aug 13 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):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----- 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.
Aug 14 2007
Chris Nicholson-Sauls wrote: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-SaulsChris, I do not want to rename the module, I want to use "str" instead of "toString". The alias is a natural solution but I do not want it imported into the caller name space. Regards, Myron.
Aug 14 2007
what abot that ? import std.string:toString; alias toString str; Myron Alexander schrieb:Chris Nicholson-Sauls wrote: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-SaulsChris, I do not want to rename the module, I want to use "str" instead of "toString". The alias is a natural solution but I do not want it imported into the caller name space. Regards, Myron.
Aug 14 2007