r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jul 19 '26
A better bitset for enum flags
https://www.elbeno.com/blog/?p=1836
46
Upvotes
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jul 19 '26
View all comments
Show parent comment
3
u/ReDucTor Game Developer | quiz.cpp-perf.com Jul 21 '26
Those operators can achieve some things however if you think of it as a set then you need other operations like difference which is
A & ~Band far from intuitive, with a set you might also have iteration of items in that set which does not exist for abitset, same with constructing from a bunch of items in a set.A lot is about naming however its also the extra set specific operations which give it more flexibility.
Pick any big enough code base and look for their usages of bitsets get used heavily as an optimization for set operations.