3 ms·
but that fails as soon as you have a case where you want to pass an algorithm implementation that does have state. That was my point - whenever I assumed that I
by jcelerier 6y ago
but that fails as soon as you have a case where you want to pass an algorithm implementation that does have state. That was my point - whenever I assumed that I would not have state... well I ended up needing to refactor everything because I ended up needing to add a new strategy that did require some state later.
In the context of C++, struct / class types are more generic that function pointers and there's no real shortcut around this - that's how the language is specified.
- steerablesafe 6y agoThere is nothing wrong with writing generic code that works both with functions and function objects. Note that stateless (empty) function objects can often be more efficient than function pointers.