T , .
, .
/ , - i, , , . v.size() size_t, T, v ≥ 2 31 ( 2 63), i . , ( 64- ), , T.
int32_t .
( OP:)
.
for (std::vector<K>::const_iterator cit = v.begin(); cit != v.end(); ++ cit) {
const K& t = *cit;
// ...
}
With Boost.Foreach you can turn this mess into
BOOST_FOREACH(const K& t, v) {
}
In C ++ 0x, this becomes a built-in function (& sect; [stmt.ranged]), but AFAIK does not support compilers; it still:
for (const K& t : v) {
}
But most compilers claiming to support C ++ 0x should allow auto:
for (auto cit = v.cbegin(); cit != v.cend(); ++ cit) {
const K& t = *cit;
}
or lambda expressions:
std::for_each(v.cbegin(), v.cend(), [](const K& t) {
...
});
source
share