www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Where in docs?

reply Paul Runde <prunde consolidated.net> writes:
This works:

struct foo(T)
{
    T x;

    void getsize()
    {
       printf("%d\n", x.size);
    }
}


void main(char[][] args)
{
    foo!(int) y;
    y.getsize();
}

I would just like to know where in the documentation this kind of 
generic programming is listed or if it is listed at all.

Thanks,

Paul
Jun 13 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
Paul Runde wrote:
 This works:
 
 struct foo(T)
 {
    T x;
 
    void getsize()
    {
       printf("%d\n", x.size);
    }
 }
 
 
 void main(char[][] args)
 {
    foo!(int) y;
    y.getsize();
 }
 
 I would just like to know where in the documentation this kind of 
 generic programming is listed or if it is listed at all.
 
 Thanks,
 
 Paul
I think you've discovered another undocumented template trick. It should be mentioned on http://www.digitalmars.com/d/template.html, but the closest thing seems to be: <quote> If a template declares exactly one member, and that member is a class with the same name as the template: template Bar(T) { class Bar { T member; } } then the semantic equivalent, called a ClassTemplateDeclaration can be written as: class Bar(T) { T member; } </quote> -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jun 13 2004
parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
"J C Calvarese" <jcc7 cox.net> escribió en el mensaje
news:caj2tv$1use$1 digitaldaemon.com
| Paul Runde wrote:
|| This works:
||
|| struct foo(T)
|| {
||    T x;
||
||    void getsize()
||    {
||       printf("%d\n", x.size);
||    }
|| }
||
||
|| void main(char[][] args)
|| {
||    foo!(int) y;
||    y.getsize();
|| }
||
|| I would just like to know where in the documentation this kind of
|| generic programming is listed or if it is listed at all.
||
|| Thanks,
||
|| Paul
|
| I think you've discovered another undocumented template trick.
|
| ...
|
| --
| Justin (a/k/a jcc7)
| http://jcc_7.tripod.com/d/

Where's the trick? struct templates? I think that's been mentioned before...

-----------------------
Carlos Santander Bernal
Jun 13 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
Carlos Santander B. wrote:

 "J C Calvarese" <jcc7 cox.net> escribió en el mensaje
 news:caj2tv$1use$1 digitaldaemon.com
 | Paul Runde wrote:
 || This works:
 ||
 || struct foo(T)
 || {
 ||    T x;
 ||
 ||    void getsize()
 ||    {
 ||       printf("%d\n", x.size);
 ||    }
 || }
 ||
 ||
 || void main(char[][] args)
 || {
 ||    foo!(int) y;
 ||    y.getsize();
 || }
 ||
 || I would just like to know where in the documentation this kind of
 || generic programming is listed or if it is listed at all.
 ||
 || Thanks,
 ||
 || Paul
 |
 | I think you've discovered another undocumented template trick.
 |
 | ...
 |
 | --
 | Justin (a/k/a jcc7)
 | http://jcc_7.tripod.com/d/
 
 Where's the trick? struct templates? I think that's been mentioned before...
 
 -----------------------
 Carlos Santander Bernal
It may have been mentioned before. My point was that I couldn't find it in the docs. I think it was possible to do the similar class syntax before it was documented. If a similar thing can be done with structs now, it should be documented. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jun 13 2004
next sibling parent "Carlos Santander B." <carlos8294 msn.com> writes:
"J C Calvarese" <jcc7 cox.net> escribió en el mensaje
news:caj93p$2aph$1 digitaldaemon.com
|
| It may have been mentioned before. My point was that I couldn't find it
| in the docs. I think it was possible to do the similar class syntax
| before it was documented. If a similar thing can be done with structs
| now, it should be documented.
|
| --
| Justin (a/k/a jcc7)
| http://jcc_7.tripod.com/d/

You're right.

-----------------------
Carlos Santander Bernal
Jun 14 2004
prev sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
J C Calvarese wrote:

 Carlos Santander B. wrote:

 It may have been mentioned before. My point was that I couldn't find 
 it in the docs. I think it was possible to do the similar class syntax 
 before it was documented. If a similar thing can be done with structs 
 now, it should be documented.
I suggest writing the amendment and sending it to the bugs forum. Parhaps there should be a d documentation amendments newsgroup. I mean, we don't get many now but if there was one I'm sure there would be many more if there was a place for it. I'm sure that would be a big help to Walter. I'll start a new thread on that matter. -- -Anderson: http://badmama.com.au/~anderson/
Jun 15 2004