Thread overview | |||||
---|---|---|---|---|---|
|
November 12, 2004 Grouping code | ||||
---|---|---|---|---|
| ||||
Hello. I'm updating my STL, and I was getting into problems again (though now I understand it a lot better). Right now I want to group some parts of the code in the following way: #class Aclass { #public: # const struct anamespace { # void something() { # ... # } # } #} So I can do Aclass a = new Aclass; a.anamespace.something(); Maybe that sounds a bit weird but I try to be a perfectionist right now ;). Anyway, the problem is accessing 'this'. Like in function 'something' I want 'this' to be applied on 'Aclass' rather than the instance of struct 'anamespace'. How would I go about that? Maybe there is a this.parent? I don't know... Wouldn't be logical. I was thinking to make a container.iterator.begin() etc, making the interfaces and so forth isn't a real problem. I'd figure making a class out of 'iterator' too which implements the interface and then get's mixed in, but then you don't get the anamespace thing. Adding a member won't work for the 'this' scope... Oh, also, I don't explicitly want hackish things, but if you know of a way... :P Maybe I'm totally not seeing something obvious right now... |
November 13, 2004 Re: Grouping code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joey Peters | "Joey Peters" <Joey_member@pathlink.com> wrote in message news:cn2m98$mkg$1@digitaldaemon.com... > Hello. > > I'm updating my STL, and I was getting into problems again (though now > I > understand it a lot better). Right now I want to group some parts of the code > in the following way: > > #class Aclass { > #public: > # const struct anamespace { > # void something() { > # ... > # } > # } > #} > > So I can do > > Aclass a = > new Aclass; > a.anamespace.something(); > > Maybe that sounds a bit weird but I > try to be a perfectionist right now ;). > Anyway, the problem is accessing > 'this'. Like in function 'something' I want > 'this' to be applied on 'Aclass' > rather than the instance of struct > 'anamespace'. How would I go about that? > Maybe there is a this.parent? I don't > know... Wouldn't be logical. I was > thinking to make a > container.iterator.begin() etc, making the interfaces and so > forth isn't a real > problem. I'd figure making a class out of 'iterator' too > which implements the > interface and then get's mixed in, but then you don't get > the anamespace thing. > Adding a member won't work for the 'this' scope... There is no direct way of adding a scoped namespace to a struct or class. But you can do it indirectly by using a mixin template. |
November 13, 2004 Re: Grouping code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | >There is no direct way of adding a scoped namespace to a struct or class. But you can do it indirectly by using a mixin template. Hmm, that just doesn't work as well as I'd want it to work. Maybe zero length argument template specifications could work like namespaces (lame)? Probably not but I can't think of anything. #class Something { #public: # int data; # template part(int optionalargument = 0) { # void print() { # printf("%i", this.data + optionalargument); # } # } #} # #int main() { # Something a = new Something; # a.part!().print(); // works # a.part.print(); // logically doesn't but would be fun if it did # a.part!(3).print(); // whahay |
Copyright © 1999-2021 by the D Language Foundation