ThePrimeagen / ts-rust-zig-deez

627 stars 162 forks source link

C++ code questions #180

Closed GFORW closed 1 year ago

GFORW commented 1 year ago

~~ Hi, whats up with that Iterator>=container.end() stuff, why check for >=, it is not supposed to work like pointers, it just gives you std::end, if you iterated to the ater the end or in case of not finding value by comparator, as i undestand, please correct me if i am wrong. (source)~~ nvm i am blind

Spongman commented 1 year ago

it's a valid question. in theory == is sufficient, but >= is more defensive. if for whatever reason the iterator skips from <= end() to >= end() then the == results in an infinite loop (well, until after size_t overflows). it "can't" happen here. until it does....