R
Rune Allnor
Hi all.
I have this data structure:
std::map<size_t,size_t> m;
std::map:<size_t,size_t>::iterator i;
In the test suite I want to loop through the elements and
test that the elements in the map contain the correct
values. So I do things like this:
i = m.begin();
BOOST_REQUIRE( i++->second == 0 );
BOOST_REQUIRE( i++->second == 1 );
The idea is that I investigate the scond field of *i, then increment
i.
It works with my implementation.
However, according to Stroustrup, the ++ post-increment and ->
dereference operators are at the same presedence level, so
in a different implementation the result might be different.
The only alternative I can come up with is
BOOST_REQUIRE( i->second == 0 ); ++i;
Is it possible to achieve what I want safely in one statement?
Rune
I have this data structure:
std::map<size_t,size_t> m;
std::map:<size_t,size_t>::iterator i;
In the test suite I want to loop through the elements and
test that the elements in the map contain the correct
values. So I do things like this:
i = m.begin();
BOOST_REQUIRE( i++->second == 0 );
BOOST_REQUIRE( i++->second == 1 );
The idea is that I investigate the scond field of *i, then increment
i.
It works with my implementation.
However, according to Stroustrup, the ++ post-increment and ->
dereference operators are at the same presedence level, so
in a different implementation the result might be different.
The only alternative I can come up with is
BOOST_REQUIRE( i->second == 0 ); ++i;
Is it possible to achieve what I want safely in one statement?
Rune