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

Usage

From this repository's own test project — built and run by CI, not written for the website.

// 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 · project tests/examples/magic_enum

Build

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

Sources (1)

  • module/magic_enum.cppm

Versions

VersionPlatforms Mirrorssha256
0.9.8 latest LinuxWindowsmacOS source 88709dc8a969…