r/ProgrammerHumor • • 11d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

Show parent comment

2

u/TerryHarris408 11d ago

what exactly does it break?

5

u/the_horse_gamer 11d ago edited 11d ago

a[0] is no longer a bool&, instead a custom type pretending to be a bool& via operator overloading

can't a.data()

can't iterate via auto&& you can, but it suffers from the same issues as the aforementioned a[0] thing

access to disjoint indices is not necessarily thread-safe

iterator may not be a LegacyForwardIterator, preventing use of many standard iterator-taking functions (with an error at compile time, or at runtime, or UB if you try)

and it's not even guaranteed to use this optimisation

3

u/Supadoplex 11d ago

can't iterate via auto&& 

I'm pretty sure you can. Did you mean auto&?

1

u/the_horse_gamer 11d ago

seems I remembered incorrectly. will fix.