Giter Club home page Giter Club logo

Comments (10)

mhbackes avatar mhbackes commented on May 18, 2024 1

@Neargye, no, definitely not.

I'm just saying that if this is ever added to the API, it should be clear (in the documentation) that the macro should not be used inside class/namespaces.

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024 1

@mhbackes you can check to customize branch https://github.com/Neargye/magic_enum/tree/customize.

I think to highlight everything in a separate namespace for customization. is this a normal name namespace magic_enum::customize?

from magic_enum.

mhbackes avatar mhbackes commented on May 18, 2024 1

@Neargye, sounds amazing.

I think the switch case is indeed the best option. This should work really well. Thanks!

from magic_enum.

mhbackes avatar mhbackes commented on May 18, 2024 1

One last question (very minor detail): does the function need to be auto?

template <>
constexpr std::string_view magic_enum::customize::enum_name<Color>(Color value) noexcept {
  switch (value) {
    case Color::RED:
      return "the red color"; // instead of `return std::string_view{"the red color"};`
    case Color::BLUE:
      return "The BLUE"; // instead of `return std::string_view{"The BLUE"};`
  }
  return ""; // instead of `return std::string_view{};`
}

I feel like declaring std::string_view as return gives a slight easier syntax.

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024 1

update in master

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024

@mhbackes

It might not be clear that you cannot declare it inside a class/namespace.

Is this functionality really necessary? First, it will clog the user class/namespace. Secondly, there may be some bad with ADL.

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024

@mhbackes how about this https://github.com/Neargye/magic_enum/blob/e7309583de648bae5a4405a422c8912ce963a114/example/example_custom_name.cpp

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024
template <>
constexpr auto magic_enum::customize::enum_name<Color>(Color value) noexcept {
  switch (value) {
    case Color::RED:
      return std::string_view{"the red color"};
    case Color::BLUE:
      return std::string_view{"The BLUE"};
  }
  return std::string_view{}; // "Empty string for default or unknow value."
}

or

MAGIC_ENUM_CUSTOM_NAME(Color::RED, "the REDcolor")
MAGIC_ENUM_CUSTOM_NAME(Color::BLUE, "the BLUEcolor")

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024
// The reason for using a function is that a switch statement is, I believe, the
// only place where a compiler will check for exhaustiveness. If you forget to
// create a case for one of the enum's constants, the compiler can let you know.

Hm, maybe the switch option will be better.

from magic_enum.

Neargye avatar Neargye commented on May 18, 2024

Yes.
I think I'll correct the syntax before taking it to the master.

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.