
Germán Diago Gómez wrote:
Hello. I'm trying to compile this code, but it doesn't do the trick and I don't know why.
Without looking into further details, the following is a misuse of enable_if:
template
struct tuple_for_each_helper { private: Tuple & t_; UnaryF f_; public: typedef typename UnaryF::result_type result_type; tuple_for_each_helper(Tuple & t, UnaryF f) : t_(t), f_(f) { }
result_type operator()(typename boost::enable_if
, void> ::type * = 0)
Here is the error: Your are trying to use enable_if/SFINAE in an "unprotected" context. What does that mean? SFINAE causes a *silent* failure during an *attempt* to instantiate a template. The only template here is tuple_for_each_helper which was already instantiated, before the actual failure could take place. a) If you want to SFINAE-shield operator(), you have to define that operator as a function template. b) If you want to prevent to SFINAE-shield the complete tuple_for_each_helper class template, you have to add one further "SFINAE" template parameter to the class template and you have to add the SFINAE expression there. It's rather easy, if you medidate about this for a while: Once an class template *is* instantiated, all member *declarations* (this is the short rule) must be valid. This is obviously not the case for the member operator(), *if* enable_if does not have a member type. Greetings from Bremen, Daniel Krügler