neargye.magic_enum
importHeader-only C++17 library for static reflection of enums, exposed as C++23 module magic_enum
import magic_enum;
mcpp add neargye.magic_enum@0.9.8
用法
來自本倉庫自己的測試專案 —— CI 真的編譯並執行過,不是為了網站寫的。
// Behavioral test: enum_name, enum_cast, enum_values under `mcpp test`.
import std;
import magic_enum;
enum class Color { RED = -10, BLUE = 0, GREEN = 10 };
int main() {
Color c = Color::RED;
auto name = magic_enum::enum_name(c);
bool ok = (name == "RED");
auto cast = magic_enum::enum_cast<Color>("GREEN");
ok = ok && cast.has_value() && cast.value() == Color::GREEN;
auto values = magic_enum::enum_values<Color>();
ok = ok && values.size() == 3;
return ok ? 0 : 1;
}
tests/examples/magic_enum/tests/reflection.cpp · 專案 tests/examples/magic_enum
建置
- modules
magic_enum- targets
magic_enum (lib)- import std
- no
- include dirs
include
原始檔 (1)
module/magic_enum.cppm
版本
| 版本 | 平台 | 鏡像 | sha256 |
|---|---|---|---|
0.9.8 最新 |
LinuxWindowsmacOS | 來源 | 88709dc8a969… |