This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/9278: dependent type in conversion operator bug
- From: David Abrahams <dave at boost-consulting dot com>
- To: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
- Cc: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>, <gcc-bugs at gcc dot gnu dot org>, <gcc-gnats at gcc dot gnu dot org>
- Date: Mon, 13 Jan 2003 21:25:30 -0500
- Subject: Re: c++/9278: dependent type in conversion operator bug
- References: <Pine.LNX.4.44.0301131824430.14794-100000@gandalf.ticam.utexas.edu>
Wolfgang Bangerth <bangerth@ticam.utexas.edu> writes:
>> > Indeed a very obscure feature. (Although, I must admit that, I desperately
>> > needed something like that not too long ago and had to invent various
>> > template metaprogramming hoops to work around...)
>>
>> I needed exactly that yesterday, which is why it came up ;-)
>> Using SFINAE to rule out certain conversions was my game, but it
>> didn't fly :(
>
> SFINAE???
"Substitution Failure Is Not An Error"
basically you can take an overload out of the overload set by causing
an invalid type computation in one of the arguments or return type:
template <bool = true, class T>
struct enable_if { typedef T type; };
template <class T>
struct enable_if<false,T> {};
// Define addition for all enums, but only for enums
template <class T>
typename enable_if<boost::is_enum<T>::value, T>::type
operator+(T x, T y) { return T(x+y); }
> In my case, I wanted to make things more uniform in Functor classes: when
> you call a function, it either returns a value, or void. So this does not
> go together
> RETTYPE ret_val = function(args)
> if RETTYPE==void. What an annoying difference, and how convenient would it
> be if there were "void variables", i.e. objects to which you can assign
> the result of a void expression :-)
Oh. But you are allowed to write "return function(args);" even if
function returns void.
> Some template trickery and specilization can get one around this, however.
Been there, done that.
--
David Abrahams
dave@boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution