🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: typeid & template func woes

#1490
From: Conrad Weyns
Date: Wed, 12 Feb 2003 20:44
99 lines
4515 bytes
"Howard Hinnant" <hinnant@metrowerks.com> skrev i melding
news:120220031147334006%hinnant@metrowerks.com...
> 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.

Yes, I learned the hard way as usual.
Interesting to observe the change in function signature as reported by
__PRETTY_FUNCTION__ after I added the second template function.

With only one function:
     template <typename T> void _report(T& _t)
        _report<long>(long &)
        _report<const long>(const long &)

With an additional function:
    template <typename T> void _report(const T& _t)
        _report<long>(long &)
        _report<long>(const long &)


It's the <long> and <const long> of the first case that got me going on thin
ice...
I must admit, I still don't get it exactly but I something that works!

>
> 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.

Thanks Howard. Had a look at that. God d... it, the things I don't know!
Time to throw everything away and start all over again...
Cheers,
Conrad Weyns.

>
> --
> Howard Hinnant
> Metrowerks
Technical Details
Message-ID: <b2ebnk$j68$1@news.dataguard.no>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news.mailgate.org!newsfeed.stueberl.de!fu-berlin.de!news.dataguard.no!not-for-mail
References: <b2dg2g$1117$1@news.dataguard.no> <macdev-B2A383.10035512022003@senator-bedfellow.mit.edu> <b2dt3k$2g0n$1@news.dataguard.no> <120220031147334006%hinnant@metrowerks.com>

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 12:44:36 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news.mailgate.org!newsfeed.stueberl.de!fu-berlin.de!news.dataguard.no!not-for-mail
From: "Conrad Weyns" <weyns@online.no>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.windows
Subject: Re: typeid & template func woes
Date: Wed, 12 Feb 2003 21:44:33 +0100
Lines: 101
Message-ID: <b2ebnk$j68$1@news.dataguard.no>
References: <b2dg2g$1117$1@news.dataguard.no> <macdev-B2A383.10035512022003@senator-bedfellow.mit.edu> <b2dt3k$2g0n$1@news.dataguard.no> <120220031147334006%hinnant@metrowerks.com>
NNTP-Posting-Host: 217.8.149.124
X-Trace: news.dataguard.no 1045082676 19656 217.8.149.124 (12 Feb 2003 20:44:36 GMT)
X-Complaints-To: news-abuse@dataguard.no
NNTP-Posting-Date: Wed, 12 Feb 2003 20:44:36 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000