Topic: Comparison operators and enums
Author: David Olsen <olsen@rational.com>
Date: 1996/02/22 Raw View
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
]