X {
X(auto _out) : out(_out) {}
int func(int x, int y, ...) {
// some stuff
return out(x,y);
}
function<int(int,int)> out = []()....
1. Is the overheard of using this instead of having out as a class function negligible?
2. Would replacing the function<> with a real function be better? (stackoverflow etc say overheard but I couldn't find it for c++17 or newer)
3. Would a lambda work instead of function? Would it be efficient?
I guess lamba is not more efficient than a normal function. You can use a compiler explorer to see what happens when you use a lambda
replace std::function with auto and see the magic
Обсуждают сегодня