c++ - Is it possible to find the number/type of the captured variables in a lambda? -
is possible automatically realize number of variables captured lambda when accessed value or reference? possible decipher types? example, assume piece of code:
int = 47; int b = 48; long long c = 49; auto f1 = [=](){ return + b; }; auto f2 = [=](){ return + b + c; };
is possible have function named count_args
returns 2
in line , 3
in next line if called below?
std::cout << count_args( f1 ) << "\n" << count_args( f2 );
no, because question implicitly assumes captured variables in fact member variables. compiler granted far more latitude. ajay notes in comments, decent optimizer can replace members hoisted expressions, , may alter types, use non-c++ types, etcetera. may capture struct color { char r,g,b }
while lambda stores .r
, .g
only. count_args
2/3rd ?
Comments
Post a Comment