I have code from here:
std::sort(begin(v), end(v), [](auto const &t1, auto const &t2) {
return get<0>(t1) < get<0>(t2); // or use a custom compare function
});
I wanted to sort tuple multiple times so I wrote this code:
int k = 10;
while(k--){
std::sort(begin(v), end(v), [](auto const &t1, auto const &t2) {
return get<k>(t1) < get<k>(t2); // or use a custom compare function
});
}
but I get error error: ‘k’ is not captured
. I tried to do it in this way:
int k = 10;
while(k--){
std::sort(begin(v), end(v), [&k](auto const &t1, auto const &t2) {
return get<k>(t1) < get<k>(t2); // or use a custom compare function
});
}
but it is not the proper way and error error: the value of ‘k’ is not usable in a constant expression
occurs.
How to capture k
variable?