|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from yaml_cpp_struct repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.0.1 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/fantasy-peak/yaml_cpp_struct.git |
| VCS Type | git |
| VCS Version | main |
| Last Updated | 2024-04-29 |
| Dev Status | UNKNOWN |
| Released | UNRELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- fantasy-peak
Authors
yaml_cpp_struct
function
It’s a wrapper, It’s easy to mapping yaml to cpp’s struct
note
main branch need >= c++17, if you need to use c++11, please use cpp11 branch. cpp11 branch not support std::variant. Please refer to example for cpp11 branch
use examples
// It relies on two other three open source libraries(yaml-cpp, visit_struct, magic_enum), Please refer to CMakeLists.txt of example
git clone https://github.com/fantasy-peak/yaml_cpp_struct.git
cd ./yaml_cpp_struct/example
mkdir build && cd build
cmake ..
make -j 9
./example ../config.yaml
// use xmake
cd ./yaml_cpp_struct/example
xmake build -v
xmake run example ../../../../config.yaml
---
ch: 'A'
price: 100.05
count: 254
content: "i'm fantasy-peak"
map: { "fantasy": "good", "peak": "good" }
account_info:
flag: false
name: "fantasy-peak"
address: { "127.0.0.1": 8888, "127.0.0.2": 9999 }
msec: 100
tuple: ["fantasy-peak", 89]
map_tuple: {"fantasy-peak": ["map_tuple", 254]}
vec: ["fantasy-001", "fantasy-002"]
set_vec: [9, 5, 7]
account_type: "Personal"
ips: ["127.0.0.1"]
#include <iostream>
#include <spdlog/spdlog.h>
#include <yaml_cpp_struct.hpp>
enum class AccountType : uint8_t {
Personal = 1,
Company = 2,
};
YCS_ADD_ENUM(AccountType, Personal, Company)
std::string to_string(const AccountType& type) {
if (type == AccountType::Personal)
return "Personal";
if (type == AccountType::Company)
return "Company";
throw std::bad_cast();
}
struct AccountInfo {
bool flag;
std::string name;
std::unordered_map<std::string, int> address;
std::optional<std::string> num;
std::chrono::milliseconds msec{100};
std::tuple<std::string, uint8_t> tuple;
std::unordered_map<std::string, std::tuple<std::string, int32_t>> map_tuple;
std::string default_str{"hello default"};
std::vector<std::string> ips;
};
YCS_ADD_STRUCT(AccountInfo, flag, name, address, num, msec, tuple, map_tuple, default_str, ips)
int main(int, char** argv) {
auto [cfg, error] = yaml_cpp_struct::from_yaml<Config>(argv[1]);
auto [str, e] = yaml_cpp_struct::to_yaml(cfg.value());
// Load values from environment variables
// export YCS_ENV_IPS=["Google","Runoob","Taobao"]
// auto [cfg, error] = yaml_cpp_struct::from_yaml_env<Config>(argv[1], "YCS_ENV_");
return 0;
}
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Launch files
Messages
Services
Plugins
Recent questions tagged magic_enum at Robotics Stack Exchange
|
magic_enum package from magic_enum repomagic_enum |
ROS Distro
|
Package Summary
| Version | 0.9.8 |
| License | MIT |
| Build type | CMAKE |
| Use | RECOMMENDED |
Repository Summary
| Description | |
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-10-05 |
| Dev Status | MAINTAINED |
| Released | RELEASED |
| Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Maintainers
- Neargye
Authors
Magic Enum C++
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
Documentation
Features & Examples
- Basic
#include <magic_enum/magic_enum.hpp>
#include <iostream>
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c1 = Color::RED;
std::cout << magic_enum::enum_name(c1) << std::endl; // RED
return 0;
}
- Enum value to string
Color color = Color::RED;
auto color_name = magic_enum::enum_name(color);
// color_name -> "RED"
- String to enum value
std::string color_name{"GREEN"};
auto color = magic_enum::enum_cast<Color>(color_name);
if (color.has_value()) {
// color.value() -> Color::GREEN
}
// case insensitive enum_cast
auto color_case_insensitive = magic_enum::enum_cast<Color>(color_name, magic_enum::case_insensitive);
// enum_cast with BinaryPredicate
auto color_with_predicate = magic_enum::enum_cast<Color>(color_name, [](char lhs, char rhs) { return std::tolower(static_cast<unsigned char>(lhs)) == std::tolower(static_cast<unsigned char>(rhs)); });
// enum_cast with default
auto color_or_default = magic_enum::enum_cast<Color>(color_name).value_or(Color::RED);
- Integer to enum value
int color_integer = 0;
auto color = magic_enum::enum_cast<Color>(color_integer);
if (color.has_value()) {
// color.value() -> Color::BLUE
}
auto color_or_default = magic_enum::enum_cast<Color>(123).value_or(Color::RED);
- Indexed access to enum value
std::size_t i = 0;
Color color = magic_enum::enum_value<Color>(i);
// color -> Color::RED
- Enum value sequence
constexpr auto colors = magic_enum::enum_values<Color>();
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
// colors[0] -> Color::RED
- Number of enum values
constexpr std::size_t color_count = magic_enum::enum_count<Color>();
// color_count -> 3
- Enum value to integer
File truncated at 100 lines see the full file
Dependant Packages
| Name | Deps |
|---|---|
| movie_publisher |