C++ 11 Range Based Loop

Repost from https://stackoverflow.com/questions/15176104/c11-range-based-loop-get-item-by-value-or-reference-to-const

If you don't want to change the items as well as want to avoid making copies, then auto const & is the correct choice:
for (auto const &x : vec)
Here is recap:
  • Choose auto x when you want to work with copies.
  • Choose auto &x when you want to work with original items and may modify them.
  • Choose auto const &x when you want to work with original items and will not modify them.

Comments

Popular posts from this blog

Ubuntu Installation Experience With Windows 8 preinstalled

How to get Xtion PRO LIVE work in Ubutun 14.04 with PCL

北美信用记录((Credit record) 的FAQ