mcpp index

neargye.magic_enum

import

Header-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

openkal

目標結果環境測試專案首條診斷
x86_64-linux-gnurunsposixmagic_enum
x86_64-windows-muslrunsposixmagic_enum

測量方式

2026-09-23 由 tests/openkal/compat.py 測得,使用 openkal-llvm-runtime 0.15.1、llvm@22.1.8、mcpp 2026.9.21.3。測試專案沒有自行選擇平台相依。 上方徽章是所有已測目標裡最嚴格那個的結果 —— 上表列出每個目標各自的環境。

建置

modules
magic_enum
targets
magic_enum (lib)
import std
no
include dirs
include

原始檔 (1)

  • module/magic_enum.cppm

版本

版本平台 鏡像sha256
0.9.8 最新 LinuxWindowsmacOS 來源 88709dc8a969…