Skip to content

eropsergeev/stringable_enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

C++17 stringable enum

Small library that lets create enums that automatically convertable to string.

Examples:

#include "stringable_enum.hpp"

namespace A {

ENUM_CLASS(Color, int, RED = 1, GREEN, BLUE = 42, NONE = -1) // declare enum class "Color" and function "to_string"

};

// Or simple enum:
// ENUM(Color, RED = 1, GREEN, BLUE = 42, NONE = -1)

std::cout << A::stringable_enum::to_string(A::Color::RED) << "\n"; // Output: RED

for (int x : A::stringable_enum::enum_values<A::Color>) { // std::array of all values as enum's base type 
    ...
}

Only integer constants allowed for values:

ENUM(Invalid, int, A = 2 + 2, B = 5) // Works, but to_string can return any option or empty string.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages