Giter Site home page Giter Site logo

Comments (6)

Neargye avatar Neargye commented on June 10, 2024 1

I’ll think about how to do it in a simpler way

from magic_enum.

Neargye avatar Neargye commented on June 10, 2024

Hi,
It seems to me that the problem here is that you are doing redefinition and not specialization

https://godbolt.org/z/dd1ePh5Yo

from magic_enum.

svew avatar svew commented on June 10, 2024

I see, maybe I misunderstood template matching relating to concepts...

Like I mentioned earlier, I was hoping to apply this customization to all of my team's enums to check whether the last item is "Count" and disregard it. Would you know of any other way to apply my rules across every enums evaluated so I don't have to identify which of our thousands of enums have "Count" and which don't? A macro switch would probably solve my problem

from magic_enum.

svew avatar svew commented on June 10, 2024

A macro switch like this for example:

namespace magic_enum::customize {

// Default customize.
inline constexpr auto default_tag = customize_t{detail::customize_tag::default_tag};
// Invalid customize.
inline constexpr auto invalid_tag = customize_t{detail::customize_tag::invalid_tag};

#if !defined(MAGIC_ENUM_CUSTOMIZE_OVERRIDE_ENUM_NAME)
  // If need custom names for enum, add specialization enum_name for necessary enum type.
  template <typename E>
  constexpr customize_t enum_name(E) noexcept {
    return default_tag;
  }
#else
  template <typename E>
  constexpr customize_t enum_name(E) noexcept;
#endif

#if !defined(MAGIC_ENUM_CUSTOMIZE_OVERRIDE_ENUM_TYPE_NAME)
  // If need custom type name for enum, add specialization enum_type_name for necessary enum type.
  template <typename E>
  constexpr customize_t enum_type_name() noexcept {
    return default_tag;
  }
#else
  template <typename E>
  constexpr customize_t enum_type_name() noexcept;
#endif

} // namespace magic_enum::customize

Besides this, I'm not sure how else to generically override customize::enum_name()

from magic_enum.

svew avatar svew commented on June 10, 2024

Actually, I'm not sure if just the above will let me achieve what I'm looking for. I was hoping to use the n<auto V>() function to grab the reflected name and check if it contains "Count", but with the customize::enum_name<typename E>(E) interface that already exists, I don't believe I'm able to grab the reflected name of the given enum value. It'd need to be customize::enum_name<typename E, E V>(), which looks like it will work fine with existing uses of customize::enum_name, but may break backwards compatibility. Any thoughts about this? I know n<auto V>() is under detail namespace so probably shouldn't be relied on, but I don't see another way right now.

Another issue is checking whether the given enum value is the last value of the enum. That sort of thing seems like it would require intercepting valid_count() before it's returned back to values() for use. It'd be nice if there were a way to do this, but I don't think it's necessary for us, so if it's too complicated then it's not a concern.

from magic_enum.

Neargye avatar Neargye commented on June 10, 2024

Unfortunately, I did not find an easy way to add this kind of customization to the library.

Probably the best way for you is fork/patch the library and update the function is_valid

Example

template <typename E, auto V>
constexpr bool is_valid() noexcept {
  constexpr auto name = n<V>();
  return name.size_ > 0 && (string_view{name.str_, name.size_}.compare("Count") != 0);
}

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.