Code Monkey home page Code Monkey logo

cppeie's Introduction

EIE - Enum Interface Extension

C++ does not have any reflection for enums, which makes it harder to maintain code.

EIE provides an interface for keeping track of an enum class's constant count and easy validity checks. Please note that EIE only works as intended for enums that have continuous values, starting at 0. EIE works at compile time and is ultra lightweight, so no overhead is created when using EIE. However, this also means that no string tables for string conversion are created, so the feature set is kept very simple.

Cloning

git clone https://github.com/RmbRT/cppeie

License

EIE is released under the GNU Affero Genereral Public License, version 3 or newer. A copy of the license file can be found in LICENSE.

Usage

In an enum class, simply wrap EIE() around the last value in the enum. This will register the enum's size and enable more sophisticated enum access.

Example:

enum class Hobbies
{
	Programming,
    EIE(Eating)
};

Enum constant count

By calling eie::count<Enum>(), the number of Enum's constants is retrieved.

int table[eie::count<Hobbies>()];

Enum value check

By calling eie::valid(), it can be determined whether an enum value is valid.

Hobbies hobby = unreliable_value();
assert(eie::valid(hobby));

Enum value loops

The eie::Range<Enum> type can be used to easily loop through all of an enum's values.

for(Hobbies hobby: eie::Range<Hobbies>())
	sophisticated(hobby);

cppeie's People

Contributors

rmbrt avatar

Stargazers

 avatar

Watchers

 avatar  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.