🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac.programmer.codewarrior
Article #1489

Re: typeid & template func woes

#1489
From: Howard Hinnant
Date: Wed, 12 Feb 2003 16:47
67 lines
3811 bytes
In article <b2dt3k$2g0n$1@news.dataguard.no>, Conrad Weyns
<weyns@online.no> wrote:

| "Miro Jurisic" <macdev@meeroh.org> skrev i melding
| news:macdev-B2A383.10035512022003@senator-bedfellow.mit.edu...
| > In article <b2dg2g$1117$1@news.dataguard.no>, "Conrad Weyns"
| <weyns@online.no>
| > wrote:
| >
| > > compiler: CW Pro 8.3 Mac & Win.
| > > issue: how can I get hold of the real type name of T that is part of a
| > > function signature in the following stripped to the bone but working
| code:
| > >
| > > Output of this running program:
| > >
| > > 1A. tA.report() gives:
| > >    function name: _report<long>(long &)
| > >    using __typeof__: long
| > >    sWoes address: 0x00420460 sWoes = 999
| > >    type of _t: long
| > >    value of _t 123
| > >
| > > 2A. tA.const_report() gives:
| > >    function name: _report<const long>(const long &)
| > >    using __typeof__: long
| > >    sWoes address: 0x00420454 sWoes = 999
| > >    type of _t: long
| > >    value of _t 123
| >
| > My understanding is that typeof (T) == typeof (const T) == typeof
| (volatile T)
| > == etc. Perhaps if you explain exactly what you are trying to do with this
| > information we can come up with an answer. (Which will involve type
| traits, I am
| > sure.)
| 
| Thanks meeroh, looks like I need to go back to school -again :-(
| Ehm, I am lying now, I never went to school!
| 
| But this was the kick in the behind that I needed to get to an alternative
| solution. I can simply differentiate between the two cases by supplying
| *two* template functions:
| 
| template <typename T> void _report(T& _t);
| template <typename T> void _report(const T& _t);
| 
| Works for me :-)

Actually the semantics of typeof haven't been worked out by the C++
committee yet.  But what meeroh says is certainly true for our current
implementation of it.

Glad you found a solution!

If it helps any further, there is a neat little type traits (hinted at
by meeroh) that lives in <msl_utility>.  You could have stuck it in
your original _report like so:

    if (Metrowerks::is_const<T>::value)
      cout << "const\n";

And it would have printed "const" for the const variants.

-- 
Howard Hinnant
Metrowerks
Technical Details
Message-ID: <120220031147334006%hinnant@metrowerks.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsfeed.cs.wisc.edu!newsfeed.mathworks.com!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!news-west.rr.com!cyclone.nyroc.rr.com!cyclone-out.nyroc.rr.com!twister.nyroc.rr.com.POSTED!53ab2750!not-for-mail
References: <b2dg2g$1117$1@news.dataguard.no> <macdev-B2A383.10035512022003@senator-bedfellow.mit.edu> <b2dt3k$2g0n$1@news.dataguard.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f635e,d1f7d1bdb1e475a0
X-Google-Attributes: gidf635e,public
X-Google-Thread: fd047,d1f7d1bdb1e475a0
X-Google-Attributes: gidfd047,public
X-Google-ArrivalTime: 2003-02-12 08:47:36 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsfeed.cs.wisc.edu!newsfeed.mathworks.com!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!news-west.rr.com!cyclone.nyroc.rr.com!cyclone-out.nyroc.rr.com!twister.nyroc.rr.com.POSTED!53ab2750!not-for-mail
Subject: Re: typeid & template func woes
From: Howard Hinnant <hinnant@metrowerks.com>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.windows
Reply-To: hinnant@metrowerks.com
Message-ID: <120220031147334006%hinnant@metrowerks.com>
References: <b2dg2g$1117$1@news.dataguard.no> <macdev-B2A383.10035512022003@senator-bedfellow.mit.edu> <b2dt3k$2g0n$1@news.dataguard.no>
Organization: Metrowerks
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: 8bit
Mail-Copies-To: nobody
User-Agent: Thoth/1.5.11 (Carbon/OS X)
X-Face: )mY~XFHLw)UOW!W#[Ljvxq6Ja7(g'#F0-g*&puNxR8hEJkd@Oue/70^.)I78\
        (%a%&Id211u"l/t.llWo/M|?15XUlx9!IGkdWiEmcasiyg"k;Q9[~XuE+`t2"*n(>nmm
        @L/q,TjMd5+H{gASEPDR^$
Lines: 67
Date: Wed, 12 Feb 2003 16:47:33 GMT
NNTP-Posting-Host: 24.24.28.73
X-Complaints-To: abuse@rr.com
X-Trace: twister.nyroc.rr.com 1045068453 24.24.28.73 (Wed, 12 Feb 2003 11:47:33 EST)
NNTP-Posting-Date: Wed, 12 Feb 2003 11:47:33 EST