We're pleased to announce the release of conjure_enum
, a lightweight header-only C++20 library designed to streamline working with enums and typenames by providing simple reflection capability.
Yes, there is magic_enum - and we based this implementation on the core of magic_enum, but refocused for C++20, using some of the key features of this newer language version such constexpr
algorithms, std::source_location
, std::to_array
and concepts
; we also improved and expanded the API.
✨Here's a closer look:
Single Header-Only: No external dependencies, simplifying integration into your project
Modern C++20: Entirely constexpr
for compile-time safety, efficiency and performance; no macros
Broad Support: Works with
- scoped and unscoped enums
- enum aliases
- gaps
- anonymous and named namespaced enums and types
Simple & Easy to Use: Class-based (rather than namespaced) approach with intuitive syntax
Convenient: enum_bitset
provides an enhanced enum aware std::bitset
Useful: conjure_type
gives you the type string of any typename
Wide Compiler Compatibility: Support for:
- GCC
- Clang
- MSVC
- XCode/Apple Clang
Testing: Includes comprehensive unit tests for reliable functionality
Expanded: Enhanced API:
- add_scope
- remove_scope
- unscoped_string_to_enum
- for_each_n
- dispatch
- iterators and more!
Transparency: Compiler implementation variability fully documented, verifiable and reportable
Full documentation: with many examples as well as example applications
Summary of main differences, including expanded API.
magic_enum | conjure_enum |
---|---|
functions within namespace | static methods within class |
pure C++20 | |
uses __PRETTY_FUNCTION__
|
uses std::source_location
|
transparent compiler specifics | |
scoped_entries | |
unscoped_entries | |
rev_scoped_entries | |
unscoped_names | |
remove_scope | |
add_scope | |
unscoped_string_to_enum | |
enum_to_string (noscope option) | |
for_each_n | |
dispatch | |
enum_bitset (string ctor with std::exception, enhanced API) | |
enum_bitset::for_each | |
enum_bitset::for_each_n | |
conjure_type | |
containers::array | |
containers::set |
Performance test vs magic_enum
We ran the following test case on a Windows 11 ThinkCentre 13th Gen Intel(R) Core(TM) i7-13700, 32Gb; MSVC 2022 / 17.10.5.
int test_magic_enum(std::errc err) { return magic_enum::enum_name(err).size(); }
int test_conjure_enum(std::errc err) { return FIX8::conjure_enum<std::errc>::enum_to_string(err).size(); }
Currently on the dev branch (will be merged to main soon):
Test | Timing |
---|---|
std::errc to string (magic_enum) | 0.385 sec |
std::errc to string (conjure_enum minimal) | 0.464 sec |
Compile ran three times, avg over 3 runs taken, linker times omitted.
Released under the MIT license.
🔗conjure_enum on github
🔗vcpkg
Top comments (0)