| Re: pointer to member as non-type template parameter: interaction with inheritance |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++.moderated · Group Profile
Author: Roman.PerepelitsaRoman.Perepelitsa Date: Mar 25, 2008 12:14
> Hello-
>
> I am trying to use SFINAE to do some introspection as to whether or
> not a class provided as a template parameter contains a given member
> function. My problem is that I would like the detection to work even
> if the class inherits from another class which defines the function.
> My problem can be boiled down to this code snippet:
>
> ------------------
> struct X {
> void f() {}
>
> };
>
> struct Y : X {};
>
> template
> struct enable {
> typedef void type;
>
> };
>
> template
> typename enable::type g() {
>
> }
>
> int main() {
> g();
> g(); //error: no matching function for call to g()}
>
> ------------------
>
> I would like this code to compile, but on gcc4, at least, the call to
> g() fails. Is there another way I could structure this example so
> that both lines are accepted by the compiler? Thanks very much.
>
> -Lewis
Take a look at is_call_possible metafunction, which was discussed
in this group before
( http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/
thread/4f7c7a96f9afbe44/e5fbc9305539f699#e5fbc9305539f699).
It does exactly what you want. If you want to detect function with
names other than 'operator()' then just replace 'operator()' with the
function name you are interested in.
Roman Perepelitsa.
|