using "next" with "auto"

Pretty simple question really; why is this giving me an error:

1
2
3
for (auto iB = next(B->begin(),B_size), lim_iB = B->end(); iB != lim_iB; iB++) {
  // error C3538: in a declarator-list 'auto' must always deduce to the same type
}


I don't see why this doesn't work; I had initially tried this:

1
2
3
for (auto iB = B->begin() + B_size, lim_iB = B->end(); iB != lim_iB; iB++) {
  // error C3538: in a declarator-list 'auto' must always deduce to the same type
}


Which also didn't work; although I would have thought the use of "next" would fix it. What could "next" possibly return other than an iterator type??

The following compiles, but it's a ugly and probably more expensive:

1
2
3
for (auto iB = next(B->begin(),B_size), lim_iB = next(B->end(),0); iB != lim_iB; iB++) {
  // error C3538: in a declarator-list 'auto' must always deduce to the same type
}

Last edited on
This was accepted as a bug by Microsoft.
https://connect.microsoft.com/VisualStudio/feedback/details/545958#details

I would guess that a Visual studio update would have fixed it.
Thanks for that. FYI the VS11 developer build no longer has this bug, but it seems vs2010 will retain it..
Topic archived. No new replies allowed.