Thread overview
Where in docs?
Jun 14, 2004
Paul Runde
Jun 14, 2004
J C Calvarese
Jun 14, 2004
J C Calvarese
Jun 15, 2004
J Anderson
June 14, 2004
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
June 14, 2004
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/
June 14, 2004
"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


June 14, 2004
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/
June 15, 2004
"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


June 15, 2004
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/