Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Check wheth...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 9324 of 10087
Post > Topic >>

Re: Check whether two functions are compatible using metaprogramming.

by David Abrahams <dave@[EMAIL PROTECTED] > Feb 28, 2008 at 05:09 PM

on Wed Feb 20 2008, Rodolfo Lima <rodlima-AT-gmail.com> wrote:

> On 19 fev, 10:59, Thomas Lehmann <t.lehm...@[EMAIL PROTECTED]
> wrote:
>
>> 2) Meta programming. I just want to know wether two types
>>     are the same or not!
>
> Unfortunately that's not what I really meant by using two functions
> interchangeably. If you make a string comparison of, say, void(*)
> (double) and int(*)(int), your metafunction will say that they're
> (rightfully) different. But say I have:
>
> int test(int a) { return a; }
>
> std::function<void(double>> f = a;
>
> It is valid and compiles, although the function signatures are
> different. I want a metafunction that tells me whether we can set a
> particular std::function to another function which signatures are
> different, but 'compatible', as is in this case.
>
> My real issue is with function overloading. Suppose I have two
> functions:
> void func(std::function<void(int)> f) {}
> void func(std::function<void(int,int)> f) {}
>
> The correct overload would only be resolved if the parameter I'm
> passing is a std::function with the correct signature. If I pass, for
> instance, a 'int test(int) {}' pointer to func, instead of resolving
> to the first overload, the compiler will say the call is ambiguous. I
> want to disambiguate this by using SFINAE, by removing the unwanted
> overload from the overload set.

It's is easy to do for function pointers: you just peel apart the type
using partial specialization and check that int is convertible to each
parameter type, but there's nothing that will tell you whether an
arbitrary function object qualifies.  Consider:

      struct f
      {
          void operator()(std::string) const {}
      };

      f x;
      func(x);

Do you care about cases like that one?


-- 
Dave Abrahams
Boost Consulting
http://boost-consulting.com

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 1 Posts in Topic:
Re: Check whether two functions are compatible using metaprogram
David Abrahams <dave@[  2008-02-28 17:09:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 16:32:59 CDT 2008.