|
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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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
| Checkout URI | https://github.com/Neargye/magic_enum.git |
| VCS Type | git |
| VCS Version | master |
| Last Updated | 2026-08-11 |
| 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 |