c++ - When using Lambdas, is it more performant to pass by value through the capture clause or through passing as a parameter? -


this question came mind, , don't know how figure out.

let me show mean:

int x = 1;  auto lambda1 = [x](){   // x, not specified here though }  auto lambda2 = [](int x){    // x, not specified here though }  lambda1(); lambda2(x); 

let's assume have either lambda1 or lambda2 @ given time.

which function faster in case? pretty sure difference minimal, if there difference @ all, caught interest , i'd know!

this might stupid ask if working 1 int, there might measurable difference in larger scaled lambdas.

the first 1 translates to

struct _ {     int x;     _(int x_): x(x_) {}     void operator()() const {...} }; 

the second 1 translates to

struct _ {     _() = default;     void operator()(int x) const {...} }; 

the former may have various effects* around closure construction site, latter may have same effects* around closure call site.

* - depends


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -