🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.mac.programmer.codewarrior
5 messages
5 total messages Started by R Shapiro Tue, 06 Feb 1996 17:58
using a template parameter as a qualifier -- legal or not?
#33
Author: R Shapiro
Date: Tue, 06 Feb 1996 17:58
33 lines
1253 bytes
I'd like to use the formal argument to a template as the qualifier of a
qualified typename within the template. This doesn't work in CodeWarrior
8, it does work in VC++ 4.0, and I can't tell from ARM whether or not it
*should* work.

Here's a more specific example:

template <class OBJECT>
class OrderedCollection {
   typedef void (OBJECT::*memberMapper)(void);
.
.
.
};

I would like the typedef 'memberMapper' to refer to pointers to member
functions (of no arguments and returning no value) of whatever class is
specified in a given instantiation of the template.

For instance, if X and Y are classes, I would expect memberMapper in
OrderedCollection<X> to be:

  void (X::*memberMapper)(void)


and memberMapper in OrderedCollection<Y> to be:

   void (Y::*memberMapper)(void)

Should this work or not? If not, why not? If so -- this is a bug in CW8.

-- 
rs/rshapiro@bbn.com
Re: using a template parameter as a qualifier -- legal or not?
#34
Author: Andrew Datars
Date: Tue, 06 Feb 1996 21:05
63 lines
2847 bytes
R Shapiro wrote:
> 
> I'd like to use the formal argument to a template as the qualifier of a
> qualified typename within the template. This doesn't work in CodeWarrior
> 8, it does work in VC++ 4.0, and I can't tell from ARM whether or not it
> *should* work.
> 
> Here's a more specific example:
> 
> template <class OBJECT>
> class OrderedCollection {
>    typedef void (OBJECT::*memberMapper)(void);
> .
> .
> .
> };
> 
> I would like the typedef 'memberMapper' to refer to pointers to member
> functions (of no arguments and returning no value) of whatever class is
> specified in a given instantiation of the template.
> 
> For instance, if X and Y are classes, I would expect memberMapper in
> OrderedCollection<X> to be:
> 
>   void (X::*memberMapper)(void)
> 
> and memberMapper in OrderedCollection<Y> to be:
> 
>    void (Y::*memberMapper)(void)
> 
> Should this work or not? If not, why not? If so -- this is a bug in CW8.
> 
> --
> rs/rshapiro@bbn.com

I have in my code something like this ...

typedef double (INTERPOLATE_DOS::*TInterpolateFunction)(double);

where INTERPOLATE_DOS is a parameter to the template.

However, I would not be that surprised if CodeWarrior doesn't
work with it. I have a little anecdote. I started trying
to use pointers to member functions of a parametrized class
about 3 years ago. At the time few compilers really had templates
working very well. With a little snippet of code I could break
many compilers. I can still use this to break certain
compilers in certain instances (where the pointer to member function
is to an overloaded function). I have not used CodeWarrior. So
I can't really comment on your question directly. I know that
for most compilers the above DOES work. But I have had the technique
actually cause the SGI compiler to crash, as well as evoke
all kinds of wacky error messages from cfront, and g++, and Borland
C++ 4.5.

Hope that helps.


Andrew
-- 
Andrew Datars	(datars@tiger.physics.utoronto.ca)
Quantum Transport/General Computer Helper		     phone:(416)978-6185
Dept. of Physics, Univ. of Toronto			     fax:  (416)978-2537
Re: using a template parameter as a qualifier -- legal or not?
#35
Author: R Shapiro
Date: Tue, 06 Feb 1996 22:11
28 lines
1537 bytes
In article <3117C2B0.41C6@tiger.physics.utoronto.ca>, Andrew Datars
<datars@tiger.physics.utoronto.ca> wrote:

>R Shapiro wrote:
>> 
>> I'd like to use the formal argument to a template as the qualifier of a
>> qualified typename within the template. This doesn't work in CodeWarrior
>> 8, it does work in VC++ 4.0, and I can't tell from ARM whether or not it
>> *should* work.
>> [example, deleted]
>


> I have not used CodeWarrior. So
>I can't really comment on your question directly. I know that
>for most compilers the above DOES work.

My first question is, *should* this work, ie is it legal according to the
more or less official C++ standard? I can't tell from my reading of ARM
and the relevant portions of the draft standard. What's your take?

The fact that other compilers support it isn't quite what I'm after, since
some compilers support things that are definitely not following the
standard. If this is a bug in CodeWarrior, I'll report it and Metrowerks
will probably fix it. But I still don't know if it really is a bug or not.

-- 
rs/rshapiro@bbn.com
Re: using a template parameter as a qualifier -- legal or not?
#36
Author: Andrew Datars
Date: Wed, 07 Feb 1996 02:16
32 lines
2274 bytes
R Shapiro wrote:
> My first question is, *should* this work, ie is it legal according to the
> more or less official C++ standard? I can't tell from my reading of ARM
> and the relevant portions of the draft standard. What's your take?
> 
> The fact that other compilers support it isn't quite what I'm after, since
> some compilers support things that are definitely not following the
> standard. If this is a bug in CodeWarrior, I'll report it and Metrowerks
> will probably fix it. But I still don't know if it really is a bug or not.
> 
> --
> rs/rshapiro@bbn.com

Well I don't know if it should be legal or not. I actually asked this
question of the net several times in my quest to use it, and I never
received a conclusive answer. The reason I think that it should be legal
is the wide support( from every compiler I have tried that was released in the
last year). Further, whenever it wasn't supported, the compiler
never reacted in a graceful manner, which leads me to believe that those
compilers hadn't considered such a use. As I said, I have crashed compilers
with it.

My suggestion would be to talk to Metrowerks.

Let me know if you find out if this is legal. I use it a lot, now that it works
and would be quite worried if this feature were to be fixed in a later release.
:)

-- 
Andrew Datars	(datars@tiger.physics.utoronto.ca)
Quantum Transport/General Computer Helper		     phone:(416)978-6185
Dept. of Physics, Univ. of Toronto			     fax:  (416)978-2537
Re: using a template parameter as a qualifier -- legal or not?
#37
Author: The Weasel
Date: Fri, 09 Feb 1996 17:43
47 lines
2361 bytes
> R Shapiro wrote:
> > 
> > I'd like to use the formal argument to a template as the qualifier of a
> > qualified typename within the template. This doesn't work in CodeWarrior
> > 8, it does work in VC++ 4.0, and I can't tell from ARM whether or not it
> > *should* work.
> > 
> > Here's a more specific example:
> > 
> > template <class OBJECT>
> > class OrderedCollection {
> >    typedef void (OBJECT::*memberMapper)(void);
> > .
> > .
> > .
> > };
> > 
> > I would like the typedef 'memberMapper' to refer to pointers to member
> > functions (of no arguments and returning no value) of whatever class is
> > specified in a given instantiation of the template.

I found this in the sep 95 working paper. This is in section 14.2 Template
name resolution.

   2 In a template, any use of a qualified-name where the qualifier depends
     on  a  template-parameter  can  be prefixed by the keyword typename to
     indicate that the qualified-name denotes a type.
          elaborated-type-specifier:

                  typename ::opt nested-name-specifier identifier 
                                 full-template-argument-listopt

   3 If a specialization of that template  is  generated  for  a  template-
     argument such that the qualified-name does not denote a type, the spe­
     cialization is ill-formed.  The keyword typename states that the  fol­
     lowing  qualified-name names a type.  [Note: but gives no clue to what
     that type might be.  ] The qualified-name shall  include  a  qualifier
     containing a template parameter or a template class name.

I have not yet tried it out w/ cw8, but the draft standard has anticipated
your usage. I hope this helps.

\p
-- 
ObDisclaimer: #include <Disclaimer.h>
ObQuote:      Chi non ha paura di morire muore una volta sola. 
                      - Giovanni Falcone
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads