digitalmars.D - Allow implicit template properties for templates with more than one member
- Jarrett Billingsley (28/28) Dec 23 2006 You can do this:
- Bill Baxter (13/29) Dec 23 2006 Yes, this would be very nice to have.
- Frits van Bommel (4/20) Dec 23 2006 This has been proposed before, but (IIRC) with the added qualification
- Daniel Keep (5/28) Dec 23 2006 Mmm; I agree with the extra restriction: the implicit property works iff...
- Thomas Kuehne (24/51) Dec 23 2006 -----BEGIN PGP SIGNED MESSAGE-----
You can do this: template Foo() { const uint Foo = 5; } ... uint x = Foo!(); And it automatically looks up Foo!().Foo because it has one member named the same as the template. What I'm suggesting is that the "have one member" part be changed. I've written and seen a lot of template code that does stuff like this: template SomethingImplementation(T, U) { alias Blah!(T) myBlah; alias Boo!(U) myBoo; ... const uint result = someNumber; } template Something(T, U) { alias SomethingImplementation!(T, U).result Something; } That is, an "implementation" template to do all the work, which has several members, and an "interface" template to make it easier to call the implementation template. Pretty kludgy. Would it really break anything if the rule were changed so that it would always just look for a member of the same name of the template, no matter how many members the template has?
Dec 23 2006
Jarrett Billingsley wrote:You can do this: template Foo() { const uint Foo = 5; } ... uint x = Foo!(); And it automatically looks up Foo!().Foo because it has one member named the same as the template. What I'm suggesting is that the "have one member" part be changed. I've written and seen a lot of template code that does stuff like this:Yes, this would be very nice to have. I find myself wishing frequently I could do something like that when dealing with non-trivial return/parameter types. template something(T) { alias [...] Ret; alias [...] A; alias [...] B; Ret something(A a, B b) { ... } } Where the [...]'s are things like typeof(T.member) or other such statically determined type based on T. --bb
Dec 23 2006
Jarrett Billingsley wrote:You can do this: template Foo() { const uint Foo = 5; } ... uint x = Foo!(); And it automatically looks up Foo!().Foo because it has one member named the same as the template. What I'm suggesting is that the "have one member" part be changed. I've written and seen a lot of template code that does stuff like this:This has been proposed before, but (IIRC) with the added qualification that all other members should be private for it to work. Still hasn't happened though :(.
Dec 23 2006
Frits van Bommel wrote:Jarrett Billingsley wrote:Mmm; I agree with the extra restriction: the implicit property works iff the template has exactly one public member with the same name as the template itself. -- DanielYou can do this: template Foo() { const uint Foo = 5; } ... uint x = Foo!(); And it automatically looks up Foo!().Foo because it has one member named the same as the template. What I'm suggesting is that the "have one member" part be changed. I've written and seen a lot of template code that does stuff like this:This has been proposed before, but (IIRC) with the added qualification that all other members should be private for it to work. Still hasn't happened though :(.
Dec 23 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Daniel Keep schrieb am 2006-12-23:Frits van Bommel wrote:The public-restriction is too weak. If implemented, it should be: The implicit property works if the template has exactly one accessible member and this member has the same name as the template. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFjdSLLK5blCcjpWoRArP6AJwIcyaiq7aN7DiYmNhiBc+tGUWpFACfcvGZ 37rJXPTczha/RJ9xjps5ytU= =nl1h -----END PGP SIGNATURE-----Jarrett Billingsley wrote:Mmm; I agree with the extra restriction: the implicit property works iff the template has exactly one public member with the same name as the template itself.You can do this: template Foo() { const uint Foo = 5; } ... uint x = Foo!(); And it automatically looks up Foo!().Foo because it has one member named the same as the template. What I'm suggesting is that the "have one member" part be changed. I've written and seen a lot of template code that does stuff like this:This has been proposed before, but (IIRC) with the added qualification that all other members should be private for it to work. Still hasn't happened though :(.
Dec 23 2006