Consider
auto x=foo(), y;
Is this legal? (I would imagine it is and implies that y
is of the same type as x
.)
While this particular example may not be very useful, consider
template<typename some_type>
void func(some_type const&x, some_type const&y)
{
for(auto i=std::begin(x),j=std::begin(y); i!=std::end(x) && j!=std::end(y); ) {
...
}
}
Here, i
and j
are both of the same type (because both derive from the same type of operation on the same type of objects), so this seems perfectly safe and sensible, as it avoids to declare the appropriate type (which is best done using decltype()
, i.e. via deduction again).
However, intel's compiler (version 14.0.1) warns me that
warning #3373: nonstandard use of "auto" to both deduce the type from an initializer and to announce a trailing return type
So, what should I make of this warning? Is there any problem that can come up with this type of usage of auto
?
edit The simple code snipped above does indeed not trigger the warning. However, the code which does looks very similar:
struct Neighbour { ... };
typedef std::vector<Neighbour> NeighbourList;
NeighbourList const&A;
NeighbourList const&B;
...
const auto K = std::max(A.size(),B.size());
auto k = 0*K;
for(auto iA=A.begin(),iB=B.begin(); k!=K; ++k,++iA,++iB)
...
(the for loop lives inside a member method of a class template)