-
Notifications
You must be signed in to change notification settings - Fork 495
Add prefix trimming #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add prefix trimming #414
Conversation
DEFINITELY As far as the
We would need to add more docs to limitations.md and change the existing docs for I am happy to do that after you have finalized what the code/API should be like. |
I mean I can add a third optional parameter for adl_info adl_info<-10,10> // min,max
adl_info<true> // is_flags
adl_info<true,10> // is_flags + prefix length
adl_info<-10,10,10> // min,max + prefix length as you noticed I don't have I don't want to go 3 adl functions route since it will slow down compilation unnecessarily (not by much given how expensive magic enum is relative to 3 adl calls) We can split the adl_info into 2 structs
sure. |
Ok now I understand the goal. Why is it necessary to provide
To be clear, I wasn't proposing having 3 ADL functions. The ADL function (the function that Instead, I was just proposing renaming
How about splitting adl_info into |
Not a limitation but if you know the prefix length then why not set the min max as well? this is what I do in my library, if you want the default anyway, set the
I think having 2 for is_flags and minmax and prefix length being the last optional parameter. having 4 combinations (you missed is_flags_prefix_length) seems a lot |
It would work for now, but it's unintuitive when reading code that uses it, and as we add more features into the struct returned by the ADL func in the future (e.g. we're adding Also worth considering: maybe just delete |
something like auto adl_magic_enum_range(Enum)
{
return magic_enum::adl_info().is_flags<true>().minmax<-100,100>().prefix_length<8>();
} |
That would be cool! Is there a way to make it work and have the members be |
template<bool IsFlags = false,int Min = MAGIC_ENUM_RANGE_MIN,int Max = MAGIC_ENUM_RANGE_MAX,std::size_t PrefixLength = 0>
struct adl_info_holder {
constexpr static int max = Max;
constexpr static int min = Min;
constexpr static bool is_flags =IsFlags;
constexpr static std::size_t prefix_length = PrefixLength;
template<int min,int max>
static adl_info_holder<IsFlags,min,max,PrefixLength> minmax() { return {};}
template<bool flag>
static adl_info_holder<flag,Min,Max,PrefixLength> flag() { return {};}
template<std::size_t PrefixLen>
static adl_info_holder<IsFlags,Min,Max,PrefixLen> prefix() { return {};}
};
adl_info_holder<> adl_info()
{
return {};
}
|
Neat! |
Let me know when you've got your final code changes in and I'll do documentation |
I am waiting for Neargye f |
Hi @ZXShady not critical, but from my logic we can simply name |
it is not required to be defined as in the docs
|
Is PR ready to merge? |
Unless I missed something, the code discussed above to allow setting
prefix_length by ADL is not yet in the tree
…On Fri, Jun 27, 2025, 4:53 AM Daniil Goncharov ***@***.***> wrote:
*Neargye* left a comment (Neargye/magic_enum#414)
<#414 (comment)>
Is PR ready to merge?
—
Reply to this email directly, view it on GitHub
<#414 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECYT6ELVQJWDEE35I6MJGL3FRTTPAVCNFSM6AAAAAB7EAL4JWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMJQGI2TMMRYG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I think it is fine to merge this then we can in a later pr revamp the adl info struct or just remove it entirely |
Ok but it's not just the adlinfo struct. If I'm looking in the right
place, the low level test for prefix_length doesn't check ADL at all right
now, so there's no way to make the setting by ADL at the moment at all. So
that would mean enums that are deep inside classes or namespaces won't be
able to take advantage of the prefix_length future like they can take
advantage of the other features like is_flags and min/max.
…On Fri, Jun 27, 2025, 10:06 AM ZXShady ***@***.***> wrote:
*ZXShady* left a comment (Neargye/magic_enum#414)
<#414 (comment)>
I think it is fine to merge this then we can in a later pr revamp the adl
info struct or just remove it entirely
—
Reply to this email directly, view it on GitHub
<#414 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECYT6GN6WQQ4YZAUMBXHAT3FSYK3AVCNFSM6AAAAAB7EAL4JWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMJRGIYTKOBTGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
In other words, if you compare line 176 and line 189 of https://github.com/ZXShady/magic_enum/blob/add_prefix_length/include/magic_enum/magic_enum.hpp the is_flags stuff checks ADL but the prefix_length stuff does not check ADL. Is that the correct source we are considering merging, or am I looking in the wrong place? |
you are right indeed it ignores prefix_length adl right now. a fix is simple adding this line template<class E>
constexpr auto prefix_length_or_zero<T,std::void_t<decltype(decltype(adl_magic_enum_define_range(E{}))::prefix_length)>> = std::size_t{decltype(adl_magic_enum_define_range(E{}))::prefix_length}; I can't currently do this as I have extremely bad internet for the next week or so |
Implements #402 Sorry @durka for the later than promised PR!
@lsemprini can you tell me what should I do with ADL info? I didn't want to add a third integral parameter I think that would be too confusing or what do you think?
Is the docs alright Daniil? I don't know how to write a decent one.
I don't have a setting to keep the prefix if turned of explicitly.
is that needed?