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 33,256 of 33,346   
   Richard to All   
   Re: What's a good, modern (c++11) argume   
   13 Nov 13 12:45:15   
   
   From: legalize+jeeves@mail.xmission.com   
      
   [Please do not mail me a copy of your followup]   
      
   "K. Frank"  spake the secret code   
   <3d9d1dcf-12ff-4ef7-9caa-3cca94802cc3@googlegroups.com> thusly:   
      
   >I guess in my own mind, I summarize it like this:   
   >   
   >1) std::function is perfectly reasonable to use for   
   >callbacks:   
   >   
   >    void registerCallback (std::function cb);   
   >   
   >2) You can templatize on the specific type of the callback:   
   >   
   >    template   
   >    void registerCallback (CallbackType cb);   
   >   
   >3) Derive callbacks from a base callback interface class:   
   >   
   >    class Callback {   
   >       public:   
   >          bool operator() (std::string) = 0;   
   >    };   
   >   
   >    void registerCallback (Callback& cb);   
      
   Something you haven't mentioned is unit testing.  There are multiple   
   libraries out there that allow you to easily mock 3), but there aren't   
   any good mock solutions for 1) or 2).   
      
   If I can easily mock the callback, I can more readily unit test the   
   code that interacts with the callback.   
   --   
   "The Direct3D Graphics Pipeline" free book    
        The Computer Graphics Museum    
            The Terminals Wiki    
     Legalize Adulthood! (my blog)    
      
      
         [ 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