Thread View: comp.std.c++
1 messages
1 total messages
Started by David Olsen
Thu, 22 Feb 1996 23:20
Comparison operators and enums
Author: David Olsen
Date: Thu, 22 Feb 1996 23:20
Date: Thu, 22 Feb 1996 23:20
38 lines
1930 bytes
1930 bytes
Consider the following snippet of code (which actually does arise in
real code since the given template operator!= is taken directly from
<utility>):
template <class T>
bool operator != (const T &x, const T &y)
{
return !(x == y);
}
enum E { a, b, c };
bool f (const E &e1, const E &e2)
{
return e1 != e2;
}
How should the compiler interpret "e1 != e2" ? Should it instantiate
the template function "operator!=(const E &, const E &)", or should it
promote x and y to int and use the built-in "operator!=(int, int)" ?
As I interpret the first paragraph of 13.3.3 in the April 95 draft, the
template function is a better match because each of its arguments are
an exact match, while the built-in operator requires a promotion for
each argument. Is this interpretation correct? If so, is this the
intention of the committee?
--
David Olsen
olsen@rational.com
---
[ To submit articles: Try just posting with your newsreader. If that fails,
use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
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