LoginSignup
2
2

C++17のモダンなループ

Last updated at Posted at 2023-11-04

C++17のモダンなループ

C++17ではモダンなループを書くことができます。例えば

for(int i=0; i<as.size(); i++) {
    std::cout << as[i] << std::endl;
}

というループは

for(auto a: as) {
    std::cout << a << std::endl;
}

と書くことがきます。autoは動的型付けしてくれます

さらに構造化束縛を使えばさらにモダンな見た目になります。

/*
Point (x, y)
*/
for(auto [xx, yy] : points) {
    処理...
}
2
2
0

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
2
2