Since most operations on std::vector
require / return size_t
- that's the type I use for indexing. But now I've enabled all compiler warnings to fix some signed / unsigned conversion issues that I know I have, and this message surprised me:
warning C4365: 'argument' : conversion from 'size_t' to '__w64 int', signed/unsigned mismatch
It was generated by this code:
std::vector<int> v;
size_t idx = 0;
v.insert(v.begin() + idx + 1, 0);
I've got a lot of other similar messages suggesting that iterator's arithmetic operators accept and return int
. Why not size_t
? Fixing all these messages is a pain, and doesn't make my code prettier!