This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 'curiously recursive template' example


As fate would have it, I included the wrong newsgroup message.  Oi. 
Everything else is correct (the .ii file and the compiler output). 
Sorry about that.


Cheers,
--binkley


Correct message:

> Path:
ndnws01.ne.mediaone.net!chnws05.ne.mediaone.net!24.128.1.91!chnws02.mediaone.net!192.148.253.68!netnews.com!news-peer1.sprintlink.net!news-in-east1.sprintlink.net!news.sprintlink.net!rpi!not-for-mail
> From: shrum@fc.hp.com (Ken Shrum)
> Newsgroups: comp.lang.c++.moderated
> Subject: Re: Guru of the Week #57: Recursive Declarations
> Date: 29 Jun 1999 14:30:17 -0400
> Organization: Hewlett-Packard Fort Collins Site
> Lines: 36
> Sender: cppmods@netlab.cs.rpi.edu
> Approved: hsutter@peerdirect.com
> Message-ID: <7laltv$ico$1@fcnews.fc.hp.com>
> References: <377768e7.19229607@nntp.netcom.ca>
> NNTP-Posting-Host: netlab.cs.rpi.edu
> X-Original-Date: 29 Jun 1999 14:41:03 GMT
> X-Submission-Address: c++-submit@netlab.cs.rpi.edu
> X-Auth: PGPMoose V1.1 PGP
> comp.lang.c++.moderatediQBVAwUAN3kQtkHMCo9UcraBAQHlNAH/XGTmKl84ZohbjteXj0q+Z9O7+LxHjckYlhYgdh9oWbjOLYM2j6CyciTZ6ixwByJYaDtZIhkvF6g2CCD2fu8EvQ===RG8U
> Xref: chnws05.ne.mediaone.net comp.lang.c++.moderated:32983
> 
> : 3. Is it possible to write a function f() that returns
> :    a pointer to itself?  It should be usable in the
> :    following natural way:
> 
> :     // FuncPtr is a typedef for a pointer to a function
> :     // with the same signature as f()
> 
> :     FuncPtr p = f();    // executes f()
> :     (*p)();             // executes f()
> 
> :    If it is possible, demonstrate how.  If it is not
> :    possible, explain why.
> 
> I'm going to restrict myself to just this one question.  This is a
> natural
> fit for a Curiously Recurring Template:
> 
> template<class T>
> struct FuncPtr_helper {
>   typedef typename T::f (*f)();
> };
> 
> struct FuncPtr_typedef : FuncPtr_helper<FuncPtr_typedef> { }
> 
> typedef FuncPtr_typedef::f FuncPtr;
> 
> FuncPtr f() {
>   return f;
> }
> 
> This may require a fair amount of smarts from the compiler to correctly
> do the type check.
> 
>     Ken Shrum
> 
>       [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
>       [ about comp.lang.c++.moderated. First time posters: do this! ]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]