diff --git a/include/bitmask/bitmask.hpp b/include/bitmask/bitmask.hpp index af04e65..d680c39 100644 --- a/include/bitmask/bitmask.hpp +++ b/include/bitmask/bitmask.hpp @@ -7,7 +7,7 @@ A generic implementation of the BitmaskType C++ concept http://en.cppreference.com/w/cpp/concept/BitmaskType - Version: 1.1.1 + Version: 1.1.2 Latest version and documentation: https://github.com/oliora/bitmask @@ -19,6 +19,8 @@ Changes history --------------- + v1.1.2: + - Fix: Can not define bitmask for a class local enum (https://github.com/oliora/bitmask/issues/3) v1.1.1: - Added missed `` header - README and code comments updated @@ -110,7 +112,7 @@ namespace bitmask { : std::integral_constant, static_cast>(T::_bitmask_value_mask)> {}; template - static constexpr underlying_type_t disable_unused_function_warnings() noexcept + inline constexpr underlying_type_t disable_unused_function_warnings() noexcept { return (static_cast(0) & static_cast(0)).bits() & (static_cast(0) | static_cast(0)).bits() @@ -290,17 +292,30 @@ namespace std } // Implementation detail macros +#define BITMASK_DETAIL_CONCAT_IMPL(a, b) a##b +#define BITMASK_DETAIL_CONCAT(a, b) BITMASK_DETAIL_CONCAT_IMPL(a, b) + +// Must be user-defined if compiler doesn't have `__COUNTER__` macro +#ifndef BITMASK_MAKE_UNIQUE_NAME +#define BITMASK_MAKE_UNIQUE_NAME(prefix) BITMASK_DETAIL_CONCAT(prefix, __COUNTER__) +#endif #define BITMASK_DETAIL_DEFINE_OPS(value_type) \ - inline constexpr bitmask::bitmask operator & (value_type l, value_type r) noexcept { return bitmask::bitmask{l} & r; } \ - inline constexpr bitmask::bitmask operator | (value_type l, value_type r) noexcept { return bitmask::bitmask{l} | r; } \ - inline constexpr bitmask::bitmask operator ^ (value_type l, value_type r) noexcept { return bitmask::bitmask{l} ^ r; } \ - inline constexpr bitmask::bitmask operator ~ (value_type op) noexcept { return ~bitmask::bitmask{op}; } \ - inline constexpr bitmask::bitmask::underlying_type bits(value_type op) noexcept { return bitmask::bitmask{op}.bits(); }\ - using unused_bitmask_ ## value_type ## _t_ = decltype(bitmask::bitmask_detail::disable_unused_function_warnings()); + inline constexpr bitmask::bitmask operator & (value_type l, value_type r) noexcept { return bitmask::bitmask{l} & r; } \ + inline constexpr bitmask::bitmask operator | (value_type l, value_type r) noexcept { return bitmask::bitmask{l} | r; } \ + inline constexpr bitmask::bitmask operator ^ (value_type l, value_type r) noexcept { return bitmask::bitmask{l} ^ r; } \ + inline constexpr bitmask::bitmask operator ~ (value_type op) noexcept { return ~bitmask::bitmask{op}; } \ + inline constexpr bitmask::bitmask::underlying_type bits(value_type op) noexcept { return bitmask::bitmask{op}.bits(); } \ + namespace bitmask_definition_detail { \ + class BITMASK_MAKE_UNIQUE_NAME(_disable_unused_function_warnings_) { \ + static constexpr int _unused() noexcept { return bitmask::bitmask_detail::disable_unused_function_warnings(), 0; } \ + }; \ + } #define BITMASK_DETAIL_DEFINE_VALUE_MASK(value_type, value_mask) \ - inline constexpr bitmask::bitmask_detail::underlying_type_t get_enum_mask(value_type) noexcept { return value_mask; } + inline constexpr bitmask::bitmask_detail::underlying_type_t get_enum_mask(value_type) noexcept { \ + return value_mask; \ + } #define BITMASK_DETAIL_DEFINE_MAX_ELEMENT(value_type, max_element) \ inline constexpr bitmask::bitmask_detail::underlying_type_t get_enum_mask(value_type) noexcept { \