Skip to content

Added efficient iterators to magic_enum::containers::bitset#450

Merged
Neargye merged 5 commits into
Neargye:masterfrom
KenanMillet:master
Jun 5, 2026
Merged

Added efficient iterators to magic_enum::containers::bitset#450
Neargye merged 5 commits into
Neargye:masterfrom
KenanMillet:master

Conversation

@KenanMillet

Copy link
Copy Markdown
Contributor

This change introduces iterators to magic_enum::containers::bitset.
The iterators utilize std::countr_zero (or compiler-based equivalents if below c++20) to efficiently determine what the next set bit is in the bitset, allowing you to iterate over all set Enum values within a bitset much faster than:

  • a magic_enum::containers::set (especially as the number of enums added to the bitset/set increases)
  • and much faster than checking each bit in the bitset individually (especially as the size of the bitset increases)

The change comes with an example, but I did not see anywhere to put benchmark tests, so I left those out.

@Neargye

Neargye commented Apr 1, 2026

Copy link
Copy Markdown
Owner

@KenanMillet Could you please check build failed?

@KenanMillet

KenanMillet commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@Neargye Made some tweaks. Addressed the clang/macos problems. Turns out they have a <intrin.h> file that is just a stub. Also fixed the windows 32 issues. Lastly, fixed some bugs that I identified after looking back at the code with fresh eyes.

@Neargye

Neargye commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Thanks, looks good!

@Neargye Neargye merged commit a9f1141 into Neargye:master Jun 5, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants