Can you use an auto deduced type where you have a comma operator to indicate initialization of two or more variables.
Yes.
Or is the presence of two initialization too confusing for a compiler?
No, it is not. As long as the auto deduction does not result in inconsistent types declaring multiple variables in the same statement using auto
is fine.
From the C++11 Standard/7.1.6.4 auto specifier/3:
auto x = 5; // OK: x has type int
const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int
However, you may not use:
const auto *v = &x, u = 6.0;
and hope for the type of v
to be deduced as const int*
and the type of u
to be deduced as const double
.