From c153854269b931cf056077359e4b7f97e76549e2 Mon Sep 17 00:00:00 2001 From: Jakob Gamper <97gamjak@gmail.com> Date: Wed, 25 Feb 2026 21:54:22 +0100 Subject: [PATCH 1/3] MSTD-93 feat: add bitflag support to MSTD enum macro --- include/mstd/enum.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/mstd/enum.hpp b/include/mstd/enum.hpp index e2cb3c3..87fb431 100644 --- a/include/mstd/enum.hpp +++ b/include/mstd/enum.hpp @@ -110,4 +110,21 @@ \ static constexpr EnumName##Meta enum_meta(EnumName) { return {}; } +#define MSTD_ENUM_BITFLAG(EnumName, Underlying, LIST) \ + MSTD_ENUM(EnumName, Underlying, LIST) \ + \ + inline EnumName operator|(EnumName lhs, EnumName rhs) \ + { \ + return static_cast( \ + static_cast(lhs) | static_cast(rhs) \ + ); \ + } \ + \ + inline EnumName operator&(EnumName lhs, EnumName rhs) \ + { \ + return static_cast( \ + static_cast(lhs) & static_cast(rhs) \ + ); \ + } + #endif // __MSTD__ENUM_HPP__ \ No newline at end of file From 567739ed6b8245c04bb72377d846b440ac98e374 Mon Sep 17 00:00:00 2001 From: Jakob Gamper <97gamjak@gmail.com> Date: Thu, 26 Feb 2026 23:38:36 +0100 Subject: [PATCH 2/3] feat: add toString method for enum conversion to string --- include/mstd/enum.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/mstd/enum.hpp b/include/mstd/enum.hpp index 87fb431..ba55f88 100644 --- a/include/mstd/enum.hpp +++ b/include/mstd/enum.hpp @@ -27,6 +27,7 @@ #include // IWYU pragma: keep #include // IWYU pragma: keep #include // IWYU pragma: keep +#include // IWYU pragma: keep #include // IWYU pragma: keep #include // IWYU pragma: keep @@ -84,6 +85,14 @@ return {}; \ } \ \ + static constexpr std::string toString(EnumName e) \ + { \ + for (std::size_t i = 0; i < size; ++i) \ + if (values[i] == e) \ + return std::string(names[i]); \ + return {}; \ + } \ + \ static constexpr std::optional from_string( \ std::string_view s \ ) \ From bbdce0a154475894f797c73c243d9a16eca65e28 Mon Sep 17 00:00:00 2001 From: Jakob Gamper <97gamjak@gmail.com> Date: Fri, 27 Feb 2026 17:01:47 +0100 Subject: [PATCH 3/3] feat: update changelog to include MSTD_ENUM_BITFLAG for enum bitwise operations --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0126e2b..12f4794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## Next Release +- introduce `MSTD_ENUM_BITFLAG` for bitwise operations on enums + ## [0.0.3](https://github.com/repo/owner/releases/tag/0.0.3) - 2026-02-08