home bbs files messages ]

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 32,897 of 33,346   
   Seungbeom Kim to Seungbeom Kim   
   Re: currying pointer to member functions   
   07 Mar 13 05:46:06   
   
   From: musiphil@bawi.org   
      
   On 2013-03-07 00:14, Seungbeom Kim wrote:   
   >   
   > So you need to write a class anyway, which is only a small step from   
   > std::mem_fun_t or your ArrowStarVoidFunc:   
   >   
   >      template    
   >      class mem_fun_obj_t   
   >      {   
   >          S (T::*memf)();   
   >          T* obj;   
   >      public:   
   >          typedef S result_type;   
   >          mem_fun_obj_t(S (T::*f)(), T* o) : memf(f), obj(o) { }   
   >          S operator()() const { return (obj->*memf)(); }   
   >      };   
   >   
   >      template    
   >      mem_fun_obj_t mem_fun_obj(S (T::*f)(), T* o)   
   >      { return mem_fun_obj_t(f, o); }   
   >   
   >      mem_fun_obj_t mfo(&a::c, &m);   
   >      std::cout << mfo() << std::endl;   
   >   
   >      std::cout << mem_fun_obj(&a::c, &m)() << std::endl;   
      
   Or you could try boost::bind and store the result in boost::function:   
      
        boost::function bf = boost::bind(&a::c, &m);   
        std::cout << bf() << std::endl;   
      
   (I tried to add this right afterwards by canceling and resubmitting,   
   but a moderation glitch didn't let it happen.)   
      
   --   
   Seungbeom Kim   
      
      
         [ 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