Declaring multiple variables within a single auto statement

Consider

auto x=foo(), y;

Is it legal? (I would suggest that this implies that it yis of the same type as x). Although this specific 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 ithey jare the same types (since both come from the same type of operations on objects of the same type), therefore it seems completely safe and reasonable, since it allows you to avoid declaring the corresponding type (it is best to use with decltype(), i.e. through deduction again).

However, the Intel 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

, ? - , auto?


edit. , , . , :

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)
  ...

( for - )

+4
3

: , y - .

: .

, : . GCC, Clang ; Intel .

+3
auto x=foo(), y;

, .

, i j . .

+4

++ 2014

... decl spec-specifier-seq declspecifier-seq init-declarators, .

+2

All Articles