Is it possible to make the function below into a lambda?
1 2 3 4 5 6 7 8 9
int digit_count(int number) {
int digits = 0;
if (number < 0) digits = 1; // remove this line if '-' counts as a digit
while (number) {
number /= 10;
digits++;
}
return digits;
}
As far as I know, you can turn pretty much any function into a lambda.
1 2 3 4 5 6 7 8 9 10 11
auto dc_lambda =
[]( int number )
{
int digits = 0;
if (number < 0) digits = 1; // remove this line if '-' counts as a digit
while (number) {
number /= 10;
digits++;
}
return digits;
};