Comments (10)
@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.
@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.
@Neargye, sounds amazing.
I think the switch case is indeed the best option. This should work really well. Thanks!
from magic_enum.
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.
update in master
from magic_enum.
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.
@mhbackes how about this https://github.com/Neargye/magic_enum/blob/e7309583de648bae5a4405a422c8912ce963a114/example/example_custom_name.cpp
from magic_enum.
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.
// 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.
Yes.
I think I'll correct the syntax before taking it to the master.
from magic_enum.
Related Issues (20)
- Is it possible to bump v0.9.4 now?
- Bazel: Might be worth removing dependency on rules_cc HOT 10
- New include path format HOT 5
- enum_flags limitation? HOT 4
- Undefined behavior HOT 1
- ostream operators do not work in all cases HOT 2
- The CMake based build does NOT install the headers to include/magic_enum?
- customize::enum_name<E>() doesn't invalidate enum items HOT 6
- Should enum_name(E value) (and maybe others?) be prevented from working with empty enums? HOT 9
- Zero value in `is_flags` enum. HOT 1
- Support for max/min Value within Enumeration. HOT 2
- Help for magic_enum with large int (example provided) HOT 1
- magic_enum::containers::array initialization doesn't work with enum containing more than 128 enum values HOT 1
- CI: hash-pin sensitive workflows and use a Dependency-Update-Tool to update them
- Regression in PR #323 HOT 1
- std::format() and std::print() support?
- Enum Range limitation : is range more than UINT16_MAX possible HOT 3
- error: cannot convert magic_enum::detail::enable_if_t HOT 1
- getting wrong results HOT 2
- Using multiple string types HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magic_enum.