Hacker News new | past | comments | ask | show | jobs | submit login

I might be in the minority here (and I don't do game development, which is the topic of this thread), but I tend to start by using `vec.get(i)` (which returns an option) and then only switch to the index notation if I end up checking the length immediately beforehand and want to do an early return or something to avoid extra indentation in the code where I use the accessed element.



I think modern C++ compilers are smart enough to eliminate the bounds check if they can prove that it never fails.


Yup, Rust will too.


I mainly do it this way to reduce the chance of my code panicking, not specifically for any performance reasons.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: