www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit template properties

reply Edward Diener <eddielee_no_spam_here tropicsoft.com> writes:
In the documentation on templates I read:

"Implicit Template Properties
If a template has exactly one member in it, and the name of that member 
is the same as the template name, that member is assumed to be referred 
to in a template instantiation:
template Foo(T)
{
T Foo; // declare variable Foo of type T
}
void test()
{
Foo!(int) = 6; // instead of Foo!(int).Foo
}"

What practical benefit does it serve having a template with a single 
member which has the same name as the template itself ? It does not 
appear that one can do anything with such a template.
Apr 13 2008
parent Edward Diener <eddielee_no_spam_here tropicsoft.com> writes:
Edward Diener wrote:
 In the documentation on templates I read:
 
 "Implicit Template Properties
 If a template has exactly one member in it, and the name of that member 
 is the same as the template name, that member is assumed to be referred 
 to in a template instantiation:
 template Foo(T)
 {
 T Foo; // declare variable Foo of type T
 }
 void test()
 {
 Foo!(int) = 6; // instead of Foo!(int).Foo
 }"
 
 What practical benefit does it serve having a template with a single 
 member which has the same name as the template itself ? It does not 
 appear that one can do anything with such a template.
Never mind ! I see the reason for it.
Apr 13 2008