Cpp-quirks Memes

Posts tagged with Cpp-quirks

Just A Bit

Just A Bit
You innocently ask std::vector<bool> to store another boolean value. Simple request, right? Just one more bit of data. But instead of being a normal, well-behaved container like every other vector type, it decides to go full chaos mode and implement a space-optimized bit-packing scheme that breaks half the STL conventions. Fun fact: std::vector<bool> doesn't actually store individual bools—it packs them into bits to save memory. Sounds great until you realize it returns proxy objects instead of references, making it not a proper STL container. It's basically the C++ committee's greatest regret, right up there with auto_ptr . That eel's expression? That's your code when you try to take the address of an element and everything implodes. Should've used std::deque<bool> or std::vector<char> instead.

The Bool Vector Is A Lie

The Bool Vector Is A Lie
So you think you understand C++? You confidently declare your std::vector<int> and life is good. But then someone mentions std::vector<bool> and suddenly you're choking on your cereal because IT'S NOT ACTUALLY A VECTOR OF BOOLS. Plot twist: C++ decided to "optimize" vector<bool> by packing bits together instead of storing actual bool objects. Sounds smart, right? WRONG. It breaks everything you thought you knew about vectors. You can't get a reference to individual elements, iterators behave like possessed demons, and it's not even a proper STL container anymore. It's basically the programming equivalent of ordering a pizza and getting a picture of a pizza instead. The C++ standards committee has openly admitted this was a mistake, but we're stuck with it forever because backwards compatibility is apparently more important than our sanity.