4 ms·
std::function is really nice. I've started using it everywhere.
by 16s 14y ago
std::function is really nice. I've started using it everywhere.
- evincarofautumn 14y agoIf only it didn’t use dynamic allocation…ah well. The value is worth the cost.
- keveman 14y agoI don't think std::function does any dynamic allocation when you initialize it with simple functions. When you initialize it with function objects or lambda expression, most, if not all implementations use the small object optimization to avoid dynamic allocation when possible.
- SamReidHughes 14y agoWith function objects the GNU std::function does do dynamic allocation. Even for objects as small as an empty struct.
- repsilat 14y agoIn this case it's probably unnecessary. It's probably better to template these higher-order functions on their function arguments and just return the lambda itself instead of returning it in a function wrapper.