4 ms·
Just as a side note: if you're looking to write a convenience wrapper like the author's transformVec, do not have it take the function as `const function<T(T)>&
by vinkelhake 13y ago
Just as a side note: if you're looking to write a convenience wrapper like the author's transformVec, do not have it take the function as `const function<T(T)>&`. Instead, do something like:
template <typename T, typename F>
vector<T> transformVec(const vector<T>& v, F op)
Using std::function in a case where you just want something callable just makes the optimizer's job a lot harder. Using std::function is a good idea if you actually need type erasure (for example if you want to pass something callable to a function that is not a template).
- Dobiasd 13y agoWow, awesome tip, thanks. This makes the wrapped version as fast as the others. I updated my article accordingly.