Boost logo

Boost Users :

Subject: [Boost-users] boost::enable_if, did I get it wrong ?
From: topoden (_dvt__at_[hidden])
Date: 2009-08-18 13:23:23


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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net