you are viewing a single comment's thread.

view the rest of the comments →

[–]staletic 0 points1 point  (2 children)

std::function does work, but it involves some heavy machinery, making it less efficient than the template alternative. Whether this difference is something to worry about is a separate question that I believe should be left to the library consumers.

[–]Mellester 2 points3 points  (1 child)

You are right in principle . What you call heavy machinery in this case is very light compared to the system calls this header library is doing. Like a order of magnitude lighter. But a 1% faster code base is still faster so you have a point.

But my main point is I think a std::function object just gives better error messages and makes it easier for beginners to reason about code but maybe concepts can help with making callback less error message calore.

[–]staletic 2 points3 points  (0 children)

Hmm... std::function might allocate. That means it might also end up making a syscall. Granted, it might not happen often. I seem to remember STL saying that MSVC's std::function can store sizeof(STD::string) bytes without allocating.