index

ref: fencepost

Fenceposts 1 foot apart. How many in 4 feet of fence?

Answer: 5.
0     1     2     3     4 
|     |     |     |     | 
|--1--|--2--|--3--|--4--| 
|     |     |     |     | 
1     2     3     4     5
Venerable source of coding errors.

Good to have a go-to paradigm for common situations:
for (int i=0;i<4;++i) // not <=.
Or:
for (int i=sz(); i;) work(--i); // Less typing, but risky if body changes.
Delete on the run:
for (auto j=T.begin(), j2; j!=T.end();) { // erase by iterator. 
  j2 = j++; 
  if (!ok(j2)) T.erase(j2); 
}

nedwaves.com 2017 [171108]