1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00
This commit is contained in:
neargye 2019-04-02 15:10:55 +05:00
parent f2c3bd8fe5
commit c74e53aabe
4 changed files with 14 additions and 6 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.6)
project(magic_enum VERSION "0.1.0" LANGUAGES CXX)
project(magic_enum VERSION "0.1.1" LANGUAGES CXX)
option(MAGIC_ENUM_OPT_BUILD_EXAMPLES "Build magic_enum examples" ON)
option(MAGIC_ENUM_OPT_BUILD_TESTS "Build and perform magic_enum tests" ON)

View file

@ -16,7 +16,7 @@
[![Build Status](https://travis-ci.org/Neargye/magic_enum.svg?branch=master)](https://travis-ci.org/Neargye/magic_enum)
[![Build status](https://ci.appveyor.com/api/projects/status/0rpr966p9ssrvwu3/branch/master?svg=true)](https://ci.appveyor.com/project/Neargye/magic-enum-hf8vk/branch/master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/64d04f150af14c3e8bd1090057b68538)](https://www.codacy.com/app/Neargye/magic_enum?utm_source=github.com&utm_medium=referral&utm_content=Neargye/magic_enum&utm_campaign=Badge_Grade)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/vvYmXey2yclPdeKM)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/gkjJ86ur57I3KOO6)
## What is Magic Enum?
@ -44,9 +44,9 @@ if (color_name.has_value()) {
// color_name.value() -> "RED"
}
constexpr auto cx_color = Color::BLUE;
constexpr auto color = Color::BLUE;
// Static storage enum variable to string enum name.
constexpr auto color_name = magic_enum::enum_to_string<cx_color>();
constexpr auto color_name = magic_enum::enum_to_string<color>();
if (color_name.has_value()) {
// color_name.value() -> "BLUE"
}
@ -61,6 +61,14 @@ if (color.has_value()) {
}
```
## Remarks
* Enum variable must be in range (-MAGIC_ENUM_RANGE, MAGIC_ENUM_RANGE). By default MAGIC_ENUM_RANGE = 128. If you need a larger range, redefine the macro MAGIC_ENUM_RANGE.
```cpp
#define MAGIC_ENUM_RANGE 1028 // Redefine MAGIC_ENUM_RANGE for larger range.
#include <magic_enum.hpp>
```
## Integration
You have to add required file [magic_enum.hpp](include/magic_enum.hpp).

View file

@ -5,7 +5,7 @@
// | | | | (_| | (_| | | (__ | |____| | | | |_| | | | | | | | |____|_| |_|
// |_| |_|\__,_|\__, |_|\___| |______|_| |_|\__,_|_| |_| |_| \_____|
// __/ | https://github.com/Neargye/magic_enum
// |___/ vesion 0.1.0
// |___/ vesion 0.1.1
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
@ -37,6 +37,7 @@
#include <string_view>
#include <optional>
// Enum variable must be in range (-MAGIC_ENUM_RANGE, MAGIC_ENUM_RANGE). If you need a larger range, redefine the macro MAGIC_ENUM_RANGE.
#if !defined(MAGIC_ENUM_RANGE)
# define MAGIC_ENUM_RANGE 128
#endif

View file

@ -13,7 +13,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(HAS_PERMISSIVE_FLAG)
set(OPTIONS ${OPTIONS} /permissive-)
endif()
set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code
set(HAS_CPP11_FLAG TRUE)
check_cxx_compiler_flag(/std:c++14 HAS_CPP14_FLAG)