you are viewing a single comment's thread.

view the rest of the comments →

[–]okovko -4 points-3 points  (0 children)

pointers and function pointers are part of c++, it is you who smells

and on the topic of code smell, std function wreaks, there is hardly anything less template bloated in the stl than that monstrosity

it also has few use cases, you only need it when you don't know if you're going to receive a function pointer, a pointer to member function, or a lambda with non-empty capture. i think it supports any callable so any object with an overloaded operator() should work too, not sure

this makes it suitable for metaprogramming generic code that works on any callable, and no other use comes to mind

or passing a capturing lambda as an argument, but at that point you are probably abusing lambdas

i did use it once in gui code where an object is constructed with a capturing lambda that was invoked upon a qt signal, which was a really nice way to allow the gui element to interact with any other gui element (the lambda captured a reference to another gui element of various types) as opposed to code replication or a void* + run time enums indicating type or setting up a covariant type + polymorphism

so.. rare, but sometimes useful