
Eric Niebler wrote:
Thorsten Ottosen wrote:
I noticed this too, and decided it was a bug in gcc. I think that given
template<typename T> struct conv { operator T() { return T(); } }; template<typename T> void bar(T&) {}
the expression:
typedef foo const cfoo; bar(true ? conv<foo>() : cfoo());
should compile,
Even though bar takes a T& and not const T& parameter?
and that in bar, T should be deduced at "foo const". With gcc, it does *not* compile because the expression "true ? conv<foo>() : cfoo()" appears to have the type "rvalue of foo" instead of "rvalue of foo const". gcc is inadvertantly dropping cv-modifiers where it shouldn't.
But we're certainly free to use that to our advantage. :-)
sure.
If we can make this work on the popular compilers, it'll be a big win for both boost.foreach and boost.typeof. It doesn't matter if we need to take advantage of compiler bugs to get it. I wonder if other compilers and other versions of gcc accept either my variant or yours.
Good question. It seems to me that conversion operators are a poorly understood part of the language. Maybe you should take this up on the reflector. Another thing I find wierd is that this seems to lead to ambiguity: template< class T > struct probe { operator T&(); operator T(); }; int main() { int i = probe<int>(); // error int& r = probe<int>(); // ok } If I add const to the T() conversion, it suddenly works ok again. -Thorsten