Git Product home page Git Product logo

Comments (4)

Neargye avatar Neargye commented on June 23, 2024 1

Hi,

MAGIC_ENUM_RANGE_MAX does not affect the maximum amount of flags.

enum_flags_* сhecks all 1<<(1 ... bit_count<Enum>) // bit_count = CHAR_BIT * sizeof(Enum)
but the limitation is that it doesn't check logical AND and '0' not сhecks

Example

enum class TestEnum {
A = 0,
B = 1,
C = 2,
D = 3,
E = 8192
};

enum_count<TestEnum>() = 4;
// '' - mean enmpty string
enum_name(TestEnum::A) = 'A'; vs enum_flags_name(TestEnum::A) = '';
enum_name(TestEnum::B) = 'B'; vs enum_flags_name(TestEnum::B) = 'B';
enum_name(TestEnum::C) = 'C'; vs enum_flags_name(TestEnum::C) = 'C';
enum_name(TestEnum::D) = 'D'; vs enum_flags_name(TestEnum::D) = 'B|C';
enum_name(TestEnum::E) = '';  vs enum_flags_name(TestEnum::E) = 'E';

enum_flags_cast('A') = nullopt; vs enum_cast('A') = TestEnum::A;
enum_flags_cast('D') = nullopt; vs enum_flags_cast('B|C') = TestEnum::D; vs  enum_cast('D') = TestEnum::D;

from magic_enum.

Benualdo avatar Benualdo commented on June 23, 2024 1

Hi @Neargye, about the zero not being included in the flags for me that's really not an issue. I mostly use magic_enum to generate UI to edit flags and the none/all cases are handled by my ImGui control anyway so I never put the 0 value in my enum flags. This is also how engines like e.g. Unity deal with C# enum flags so I got used to have MyEnum val = (MyEnum)0 instead of having a MyEnum::None entry in the enum flags.

from magic_enum.

Neargye avatar Neargye commented on June 23, 2024

I'll add a documentation update later.

from magic_enum.

Neargye avatar Neargye commented on June 23, 2024

@Benualdo could you tell me what you think about the restriction that zero is not included in the flags? #321

from magic_enum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.