public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Arbitrary function as template parameter?
@ 2003-09-26  2:56 Lally Singh
  2003-09-26  4:13 ` Phil Edwards
  2003-09-26  6:31 ` [Solved] " Lally Singh
  0 siblings, 2 replies; 3+ messages in thread
From: Lally Singh @ 2003-09-26  2:56 UTC (permalink / raw)
  To: gcc

Hi.  I'm writing a g++ extension to give more type information via a 
'special' template type_description<>.  Yeah, 'special' templates are 
kludge-esque, but I was able to figure out how to do it this way faster 
than via more __builtins.

I can do this:

struct foo {};

int i = std::type_description<foo>::is_pod;

But I can't do this:

int foo();

typename std::type_description<foo>::return_type	val = foo();


As parser.c (while very readable) scares me, I'd rather not do any 
changes to the grammar.  So, can I declare a template to either take in 
a type or a function, or at least another template that can take an 
arbitrary function as a parameter?


-- 
Life is short, give up early.


--  
Government is not reason, it is not eloquence, it is force; like fire, 
a troublesome servant and a fearful master.  Never for a moment should 
it be left to irresponsible action.
- George Washington

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Arbitrary function as template parameter?
  2003-09-26  2:56 Arbitrary function as template parameter? Lally Singh
@ 2003-09-26  4:13 ` Phil Edwards
  2003-09-26  6:31 ` [Solved] " Lally Singh
  1 sibling, 0 replies; 3+ messages in thread
From: Phil Edwards @ 2003-09-26  4:13 UTC (permalink / raw)
  To: lallysingh; +Cc: gcc

On Thu, Sep 25, 2003 at 08:21:20PM -0400, Lally Singh wrote:
> Hi.  I'm writing a g++ extension to give more type information via a 
> 'special' template type_description<>.  Yeah, 'special' templates are 
> kludge-esque, but I was able to figure out how to do it this way faster 
> than via more __builtins.

See http://www.devphil.com/~pme/reflection.html and search these lists'
archives for mention of the cxx-reflection development branch.


> As parser.c (while very readable) scares me, I'd rather not do any 
> changes to the grammar.  So, can I declare a template to either take in 
> a type or a function, or at least another template that can take an 
> arbitrary function as a parameter?

Nope, not without changes to the grammar.

-- 
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
    - Brian W. Kernighan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Solved] Re: Arbitrary function as template parameter?
  2003-09-26  2:56 Arbitrary function as template parameter? Lally Singh
  2003-09-26  4:13 ` Phil Edwards
@ 2003-09-26  6:31 ` Lally Singh
  1 sibling, 0 replies; 3+ messages in thread
From: Lally Singh @ 2003-09-26  6:31 UTC (permalink / raw)
  To: lallysingh; +Cc: gcc

Ok.  Never mind :-)
std::type_description<__typeof__(foo)> should do what I want..

--  
Government is not reason, it is not eloquence, it is force; like fire, 
a troublesome servant and a fearful master.  Never for a moment should 
it be left to irresponsible action.
- George Washington

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-26  2:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-26  2:56 Arbitrary function as template parameter? Lally Singh
2003-09-26  4:13 ` Phil Edwards
2003-09-26  6:31 ` [Solved] " Lally Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).