Topic: does is_polymorphic work ?


Author: user name <user182@MailAndNews.com>
Date: Sat, 28 Apr 2001 10:56:06 GMT
Raw View
A while ago Christopher Eltschka posted some code which
was supposed to determine if an object was polymorphic or not.

template<class T> bool is_polymorphic()
{
  bool result = false;
  typeid(result = true, T());
  return result;
}

Which was modified by a few subsequent posters to be this.

template<class T> bool is_polymorphic( const T&r )
{
  bool result = false;
  typeid(result = true, r);
  return result;
}

I cannot find the language in the standard that
says that this code should work.

The best I can find is some text around the ODR

3.2 /2

  "An expression is potentially evaluated unless either it is the
   operand of the sizeof operator (5.3.3), or it is the operand
   of the typeid operator and does not designate an lvalue of
   polymorphic class type (5.2.8)..."

This seems to be what is_polymorphic hinges on.

The problem is that "potentially evaluated" in this context isn't
natural English.  "potentially evaluated" is just a placeholder
that describes a set of expressions.  And then that set is used
to describe a set of "used" objects or functions.

"Used" in that context does not mean something gets evaluated
does it ?

Is there some other place in the standard that has language
that assures us that is_polymorphic will work and "result = true"
won't be evaluated for non-polymorphic types (and will be otherwise) ?
Because its my feeling that the wording in ODR is too weak to bless
is_polymorphic.

That being said, I think is_polymorphic is great idea, and I would
love to see the standard ensure that it works.

Thanks.

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Andrea Ferro" <AndreaF@UrkaDVD.it>
Date: Sun, 29 Apr 2001 13:19:55 GMT
Raw View
"user name" <user182@MailAndNews.com> wrote in message
news:3AF7D6BA@MailAndNews.com...
> A while ago Christopher Eltschka posted some code which
> was supposed to determine if an object was polymorphic or not.
..
> I cannot find the language in the standard that
> says that this code should work.
>
> The best I can find is some text around the ODR
>
> 3.2 /2
...
> This seems to be what is_polymorphic hinges on.
...
> Is there some other place in the standard that has language
> that assures us that is_polymorphic will work and "result = true"
> won't be evaluated for non-polymorphic types (and will be otherwise) ?
> Because its my feeling that the wording in ODR is too weak to bless
> is_polymorphic.

Have a look to 5.2.8, expecially the very last sentence of 5.2.8 sub 3.

--

Andrea Ferro

---------
Brainbench C++ Master. Scored higher than 97% of previous takers
Scores: Overall 4.46, Conceptual 5.0, Problem-Solving 5.0
More info http://www.brainbench.com/transcript.jsp?pid=2522556



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]