You can only apply enable_if to template arguments of the function and not of the class which contains the function, but you can't declare a virtual function template... So this is your dilemma.

Regards,
Ovanes

On Tue, Aug 18, 2009 at 7:23 PM, topoden <_dvt_@mail.ru> wrote:

Hello,

I'm trying to use boost::enable_if to customize function declaration for a
particular set of template arguments. But instead of using SFINAE to remove
incorrect declaration it produces error. See the example below to see better
what I mean:

#include <boost/utility.hpp>
#include <boost/type_traits.hpp>

template<class A, class B>
struct BaseListener
{
       typename boost::disable_if<boost::is_void< B >, void>::type
       void virtual process(A *, B *) = 0;

       typename boost::enable_if<boost::is_void< B >, void>::type
       void virtual process(A *) = 0;
};

struct Request
{
};

struct Response
{
};

typedef BaseListener<Response, void> BaseResponseListener;
typedef BaseListener<Request, BaseResponseListener> BaseRequestListener;

struct RequestListener : public BaseRequestListener
{
       void process(Request *, BaseResponseListener *)
       {
       }
};

struct ResponseListener : public BaseResponseListener
{
       void process(Request *)
       {
       }
};

int main(int argc, char * argv[])
{
       RequestListener reqListener;
       ResponseListener resListener;

       return 0;
}

error message:
error C2039: 'type' : is not a member of 'boost::enable_if<Cond,T>'
1>        with
1>        [
1>            Cond=boost::is_void<BaseResponseListener>,
1>            T=void
1>        ]
1>        c:\!projects\temp\consoleeventhandler\consoleeventhandler.cpp(134)
: see reference to class template instantiation 'BaseListener<A,B>' being
compiled
1>        with
1>        [
1>            A=Request,
1>            B=BaseResponseListener
1>        ]
--
View this message in context: http://www.nabble.com/boost%3A%3Aenable_if%2C-did-I-get-it-wrong---tp25027913p25027913.html
Sent from the Boost - Users mailing list archive at Nabble.com.

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users