Boost logo

Boost :

Subject: [boost] [mpl] has_function
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-03-21 09:11:31


Hello all,

Is there a way I can check if a class has a given member function
using metaprogramming?

What I need is to check at compile-time if a function is overriding a
virtual function or not. In the example below, z::f is overriding x::f
but not y::f (which does not exist) and the compiler knows that -- is
there a way I can extract that information from the compiler?

    struct has_function<class Base, ... /* other parameters */ > { ...
/* some implementation */ };

    struct x {
        virtual void f() {}
    };

    struct y {
        virtual void g() {}
    };

    struct z: x, y {
        void f() {
            cout << has_function<x, &z::f>::value << endl; // print 1
            cout << has_function<y, &z::f>::value << endl; // print 0
        }
    };

(This does not compile -- I do not know how to program it so it
compiles -- but it should give the idea of what I am looking for.)

Thank you very much.
Lorenzo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk