Allow implicit template properties for templates with more than one member

Thomas Kuehne thomas-dloop at kuehne.cn
Sat Dec 23 16:26:42 PST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Keep schrieb am 2006-12-23:
> Frits van Bommel wrote:
>> 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 :(.
>
> 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.

The public-restriction is too weak.

#
# struct Foo{ int i = 1; }
#
# template Bar(){
#     private int i = 2;
#     public Foo Bar;
# }
#
# [...]
#
# int x = Bar.i; // 1 or 2?

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-----



More information about the Digitalmars-d mailing list