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,262 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: How to convert a typedef to a std::f   
   09 May 12 14:57:44   
   
   a3d66e46   
   From: daniel.kruegler@googlemail.com   
      
   Am 09.05.2012 21:27, schrieb Peter:   
   > Hi Folks,   
   >   
   > given this typedef   
   >   
   > typedef bool (*on_hit_test_type)(widget_interactive *, point const*,   
   > bool *);   
   >   
   > and this member definition   
   >   
   > std::function   
   > on_hit_test;   
   >   
   > Is there a way to convert one to the other? (The typedef to the   
   > std::function template argument or the other way round)   
      
   Do you mean something like this:   
      
   std::function::type> on_hit_test;   
      
   in one direction? The other direction requires a little more efforts:   
   You could invent a small trait like the following   
      
   template   
   struct function_signature;   
      
   template   
   struct function_signature>   
   {   
     typedef R type(Args...);   
   };   
      
   Now you are able to go backwards via:   
      
   typedef std::add_pointer::type>::type fu_ptr;   
      
   The following assertion should hold:   
      
   static_assert(std::is_same::value, "");   
      
   > The reason I'm asking is that I have a ton of them, and it's easy to   
   > make errors in these somwhat duplicate constructs.   
   >   
   > Ideally, I'd like to write one and derive the other somehow from it.   
      
   I don't understand how you mean this - how is derivation related to that?   
      
   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