我知道boost或编译器应该是最后的责任,但我在这里看不到另一种解释.我正在使用msvc 2008 SP1并提升1.43.
在下面的代码片段中,执行永远不会离开第三个 BOOST_FOREACH循环
typedef Graph<unsigned, unsigned>::VertexIterator Iter;
Graph<unsigned, unsigned> g;
g.createVertex(0x66);
// works fine
Iter it = g.getVertices().first, end = g.getVertices().second;
for(; it != end; ++it)
;
// fine
std::pair<Iter, Iter> p = g.getVertices();
BOOST_FOREACH(unsigned handle, p)
;
// fine
unsigned vertex_count = 0;
BOOST_FOREACH(unsigned handle, g.getVertices())
vertex_count++;
// oops, infinite loop
vertex_count = 0;
BOOST_FOREACH(unsigned handle, g.getVertices())
vertex_count++;
vertex_count = 0;
BOOST_FOREACH(unsigned handle, g.getVertices())
vertex_count++;
// ... last block repeated 6 times
Run Code Online (Sandbox Code Playgroud)
迭代器代码:
class Iterator
: …Run Code Online (Sandbox Code Playgroud)