Boost logo

Boost :

Subject: Re: [boost] [mpl] has_function
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-03-21 11:51:41


Hi,
----- Original Message -----
From: "Lorenzo Caminiti" <lorcaminiti_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, March 21, 2010 2:11 PM
Subject: [boost] [mpl] has_function

>
> 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.)

maybe you can take a look at
https://svn.boost.org/trac/boost/wiki/LibrariesUnderConstruction#Boost.ConceptTraits

This library was abandoned because Concepts will be part of the language. It contains alot of traits about if a class ddefines a function. I don't know if there is some some traits for virtual functions.

Let us know,
Vicente


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