cm0002@lemmy.world to Programmer Humor@programming.dev · 7 天前Tell me the truth ...piefed.jeena.netimagemessage-square165linkfedilinkarrow-up11.17Karrow-down117
arrow-up11.16Karrow-down1imageTell me the truth ...piefed.jeena.netcm0002@lemmy.world to Programmer Humor@programming.dev · 7 天前message-square165linkfedilink
minus-squaretimhh@programming.devlinkfedilinkarrow-up24·6 天前Well there are containers that store booleans in single bits (e.g. std::vector<bool> - which was famously a big mistake). But in the general case you don’t want that because it would be slower.
minus-squareethancedwards8@programming.devlinkfedilinkEnglisharrow-up7·6 天前Why is this a big mistake? I’m not a c++ person
minus-squarebitcrafter@programming.devlinkfedilinkarrow-up5·6 天前The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways.
minus-squareethancedwards8@programming.devlinkfedilinkEnglisharrow-up3arrow-down1·6 天前Could you provide an example?
minus-squaretimhh@programming.devlinkfedilinkarrow-up1·2 天前The biggest problem is that each element doesn’t have a unique memory address; iterators aren’t just pointers.
Well there are containers that store booleans in single bits (e.g.
std::vector<bool>
- which was famously a big mistake).But in the general case you don’t want that because it would be slower.
Why is this a big mistake? I’m not a c++ person
The mistake was that they created a type that behaves like an array in every case except for
bool
, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways.Could you provide an example?
The biggest problem is that each element doesn’t have a unique memory address; iterators aren’t just pointers.