Git Product home page Git Product logo

cppstringenum's Introduction

Require

c++11 or __VA_ARGS__ compiler support.

It doesn't works on c99.

How to use

#include<iostream>
#include<string>
#include"stringEnum.h"
using namespace std;

STRING_ENUM(Week,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday)

int main(){
    Week::Enum day = Week::Sunday;
    cout<<"Today is "<<Week::getString(day)<<endl;
    string nextDay[] = {"Monday","asdiuhnkjc"};
    for(auto next:nextDay){
        try{
            if(Week::getEnum(next)==Week::Monday){
                cout<<"Go to work"<<endl;
            }
        }
        catch(invalid_argument &e){
            cout<<"error"<<endl;
        }
    }
}

//output:
//Today is Sunday
//Go to work
//error

You can separate the definition and declaration:

//in .h
#define List Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
STRING_ENUM_DECLARE(Week,List)

//in .cpp
STRING_ENUM_DEFINE(Week,List)

Note

The number of enum members is limited to 200.

cppstringenum's People

Contributors

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