Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,719 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Rune Allnor    |
|    Re: Does Boost.Bind work with arguments     |
|    05 Dec 11 15:47:25    |
   
   4657480e   
   From: daniel.kruegler@googlemail.com   
      
   On 2011-12-05 06:37, Rune Allnor wrote:   
   > I'm trying to implement a function object (not a free   
   > function) that takes takes function pointers as   
   > argument:   
   >   
   > class MyClass{   
   > public:   
   > double operator()(double x,double f1(double)){ return f(x)+1;};   
   > }   
   >   
   > where f1 is a function to be specified by the user   
   > of this class.   
      
   More specifically, f1 has type function pointer double(*)(double), so   
   you need an argument that is convertible to that pointer type.   
      
   > When I attempt to call this as   
   >   
   > class c1{   
   > public:   
   > double F1(double x){return x*x;};   
   > }   
   >   
   > MyClass a;   
   > c1 b;   
   >   
   > double y = a(3.14,boost::bind(&c1::F1,_1)); //<<< Compiler error   
      
   I understand that this is ill-formed code but I'm failing to understand   
   what you want to realize.   
      
   1) c1::F1 is a binary function, so you probably meant to bind two   
   arguments, e.g. boost::bind(&c1::F1,_1, 1.2) instead, no?   
      
   2) Whatever you intended, I have a hard time to understand how you can   
   expect that a usual function object of class type *which is stateful*   
   can be converted to a function pointer. I hope you don't want to suggest   
   that global state should be somehow provided for that.   
      
   > the compiler complains in all sorts of ways.   
   > I am using VS2008 and have defined all the   
   > proprocessefinitions that are mentioned in the   
   > docs of boost.bind.   
      
   Please clarify more precisely what you want here.   
      
   > When I re-read the docs for boost.bind it mentions   
   > that the library is intended for use with the STL   
   > algorithms, that is, free functions as opposed   
   > to function objects.   
      
   I do not understand what you are trying to say here, but boost::bind (or   
   std::bind for that matter) can adapt any function object (including   
   function pointers, class types with overloaded operator() or a   
   conversion function to function pointer as well as pointer to members)   
   to another class type that is a function object with a different   
   signature, typically one with less arguments. This also means, that the   
   result of bind generally is a stateful function object. Given that, what   
   kind of function pointer could such an object be converted to?   
      
   > Is this important at all? What, if anything,   
   > can be done to make this work?   
      
   In most parts I have problems following you here, so I cannot properly   
   respond to this question.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca