GithubHelp home page GithubHelp logo

enumfactory's Introduction

Based on: https://stackoverflow.com/a/202511/1479945 (by @Suma)

This one compiles on a piece of wood (unlike e.g. the finicky magic_enum.hpp),
it's just plain C. And requires basically nothing (unlike e.g. Debdatta Basu's
stringizer, that can't even do more than that). Nice.
(Examples test-compiled cleanly with c++11, c++17.)


Changes to the original:

- Added the missing string.h.
- Renamed getname to be consistent with its pair.
- Eliminated the use of DEFINE_ENUM in the cpps.
- Eliminated DECLARE_ENUM altogether.
- Reversed the arg order of DEFINE_ENUM to be more natural
  when calling the X macro sg. like <my enumtype>_DEF.
  - But I don't like it better this way after all. :)
- Added include guards.
- Also applied pmttavara's great suggestion: https://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c/202511#comment83003525_202511
  - So, no more "which arg order" dilemma! :)
- Refactored to be more self-describing.

TODO:

- Use __VA_OPT__ now to eliminate those ugly trailing commas.
- Test/add enum class support.
- Test/add enum-in-a-class support.
  -> Can't do either implicitly. Would require shifting to C++;
     either -> enumfactory.hpp, or enumfactory++.h

enumfactory's People

Contributors

xparq avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.