8 June 2005
Generalized functors
Required reading for C++ programmers: Alexandrescu's Modern C++ Design. I've been re-reading his chapter on generalized functors in the hope of seeing how I could have improved my recent code with abstracted database access. I wrapped specific MFC database actions in functions or function objects that are passed to a main function for execution. The main function catches the different MFC errors and checks return codes, then converts them into a custom exception hierarchy. This simplified the main code by eliminating multiple exception handlers around the code and multiple error checks inside the code. However, my function objects had limited versatility because their signatures had to stay the same.
Alexandrescu's generalized functors would have been ideal. He has created a small library that can wrap every type of callable entity (C functions, C function pointers, references to functions, functors, and member functions), along with parameter binding, in a single template. Very nice.
- Techniques after using Swift for a month posted by sstrader on 26 August 2015 at 11:41:51 PM
- Some thoughts on Ruby after finishing a week (minus one day) of training posted by sstrader on 15 December 2011 at 8:59:30 PM
- Links on the singleton pattern posted by sstrader on 9 December 2011 at 9:19:50 AM
- Phonebot posted by sstrader on 29 October 2011 at 6:37:05 PM
- The labeled break in Java posted by sstrader on 4 September 2011 at 11:27:56 AM