Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: printing te...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 12 Topic 9581 of 9831
Post > Topic >>

Re: printing template argument

by Edward Rosten <Edward.Rosten@[EMAIL PROTECTED] > May 13, 2008 at 10:53 AM

On May 8, 3:31 am, Venkat <swara...@[EMAIL PROTECTED]
> wrote:
> Hello,
>
>   I'm wondering about how to print the name of the template argument in
> a template method.

Not in general.

There's a hack based on a gcc extension that works, though:

template<class T> string type_name()
{
         string s= __PRETTY_FUNCTION__;

         int p1 = s.find('[');
         int p2 = s.rfind(']');

         return s.substr(p1 + 9, p2-p1-9);
}

It's generally good enough for debugging purposes. You might have to
tweak 9 for different GCC versions.

-Ed
--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
     d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 12 Posts in Topic:
printing template argument
Venkat <swara101@[EMAI  2008-05-08 03:31:00 
Re: printing template argument
Alex <aleskx@[EMAIL PR  2008-05-08 09:03:56 
Re: printing template argument
mcostalba <mcostalba@[  2008-05-08 09:13:27 
Re: printing template argument
Venkat <swara101@[EMAI  2008-05-08 21:27:56 
Re: printing template argument
Joe Gottman <jgottman@  2008-05-08 21:38:44 
Re: printing template argument
Sarang <sarangbaheti@[  2008-05-09 09:22:32 
Re: printing template argument
Stuart Golodetz <sgolo  2008-05-09 21:13:46 
Re: printing template argument
Seungbeom Kim <musiphi  2008-05-09 21:22:54 
Re: printing template argument
Sean Hunt <rideau3@[EM  2008-05-09 21:23:14 
Re: printing template argument
Greg Herlihy <greghe@[  2008-05-10 06:14:40 
Re: printing template argument
Pete Becker <pete@[EMA  2008-05-10 14:13:29 
Re: printing template argument
Edward Rosten <Edward.  2008-05-13 10:53:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:01:38 CDT 2008.