This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/9278: dependent type in conversion operator bug


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]