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

构建

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

源文件 (1)

  • module/magic_enum.cppm

版本

版本平台 镜像sha256
0.9.8 最新 LinuxWindowsmacOS 源站 88709dc8a969…