LoginSignup
3

More than 5 years have passed since last update.

イテレータの回し方

Last updated at Posted at 2013-10-19

今までイテレータ回す時

for (std::vector<int>::iterator it = v.begin() ; it < v.end(); ++it) {
  // hogefuga
}

って書いてたけど

for (std::vector<int>::iterator it = v.begin() ; it != v.end(); ++it) {
  // hogefuga
}

なんですね。itがv.end()以下かではなくて、itがv.end()ではないかで判断すべき。
もっと簡単に書く方法もあって、

for (auto it = v.begin(); it != v.end(); ++it) {
  // hogefuga
}

こんな感じでautoを使うと便利。このときconstはどうなるんだろう。ブロック内で変更がなければ自動的にconstつけてくれたりするんだろうか。そこまではしないか。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3