Merge pull request #11 from BlackMATov/dev

Dev
This commit is contained in:
2021-08-06 02:04:58 +07:00
committed by GitHub
6 changed files with 39 additions and 32 deletions

View File

@@ -10,16 +10,14 @@ jobs:
matrix:
config:
# https://github.com/actions/virtual-environments/tree/main/images/linux
- { os: "ubuntu-18.04", cc: "gcc-7", cxx: "g++-7" }
- { os: "ubuntu-18.04", cc: "gcc-8", cxx: "g++-8" }
- { os: "ubuntu-18.04", cc: "gcc-9", cxx: "g++-9" }
- { os: "ubuntu-18.04", cc: "gcc-10", cxx: "g++-10" }
- { os: "ubuntu-18.04", cc: "clang-5.0", cxx: "clang++-5.0" }
- { os: "ubuntu-18.04", cc: "clang-6.0", cxx: "clang++-6.0" }
- { os: "ubuntu-18.04", cc: "clang-7", cxx: "clang++-7" }
- { os: "ubuntu-18.04", cc: "clang-8", cxx: "clang++-8" }
- { os: "ubuntu-18.04", cc: "clang-9", cxx: "clang++-9" }
- { os: "ubuntu-18.04", cc: "clang-10", cxx: "clang++-10" }
- { os: "ubuntu-20.04", cc: "gcc-7", cxx: "g++-7" }
- { os: "ubuntu-20.04", cc: "gcc-8", cxx: "g++-8" }
- { os: "ubuntu-20.04", cc: "gcc-9", cxx: "g++-9" }
- { os: "ubuntu-20.04", cc: "gcc-10", cxx: "g++-10" }
- { os: "ubuntu-20.04", cc: "clang-7", cxx: "clang++-7" }
- { os: "ubuntu-20.04", cc: "clang-8", cxx: "clang++-8" }
- { os: "ubuntu-20.04", cc: "clang-9", cxx: "clang++-9" }
- { os: "ubuntu-20.04", cc: "clang-10", cxx: "clang++-10" }
name: "${{matrix.config.cxx}}"
steps:
- name: Setup

View File

@@ -11,6 +11,17 @@ add_library(${PROJECT_NAME} INTERFACE)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_include_directories(${PROJECT_NAME} INTERFACE headers)
target_compile_options(${PROJECT_NAME}
INTERFACE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wno-c++98-compat-pedantic
-Wno-covered-switch-default
-Wno-ctad-maybe-unsupported
-Wno-old-style-cast
-Wno-shadow
-Wno-unknown-warning-option
-Wno-weak-vtables>)
if(BUILD_AS_STANDALONE)
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
if(BUILD_WITH_UNTESTS)

View File

@@ -41,7 +41,7 @@
## Requirements
- [gcc](https://www.gnu.org/software/gcc/) **>= 7**
- [clang](https://clang.llvm.org/) **>= 5.0**
- [clang](https://clang.llvm.org/) **>= 7**
- [msvc](https://visualstudio.microsoft.com/) **>= 2017**
## Installation

View File

@@ -260,30 +260,28 @@ namespace enum_hpp::detail
{ ENUM_HPP_GENERATE_NAMES(Fields) }\
};\
public:\
static constexpr underlying_type to_underlying(enum_type e) noexcept {\
[[maybe_unused]] static constexpr underlying_type to_underlying(enum_type e) noexcept {\
return static_cast<underlying_type>(e);\
}\
\
static constexpr std::optional<std::string_view> to_string(enum_type e) noexcept {\
[[maybe_unused]] static constexpr std::optional<std::string_view> to_string(enum_type e) noexcept {\
switch ( e ) {\
ENUM_HPP_GENERATE_VALUE_TO_NAME_CASES(Enum, Fields)\
default: return std::nullopt;\
}\
}\
static constexpr std::string_view to_string_or_empty(enum_type e) noexcept {\
[[maybe_unused]] static constexpr std::string_view to_string_or_empty(enum_type e) noexcept {\
if ( auto s = to_string(e) ) {\
return *s;\
}\
return ::enum_hpp::empty_string;\
}\
static std::string_view to_string_or_throw(enum_type e) {\
[[maybe_unused]] static std::string_view to_string_or_throw(enum_type e) {\
if ( auto s = to_string(e) ) {\
return *s;\
}\
::enum_hpp::detail::throw_exception_with(#Enum "_traits::to_string_or_throw(): invalid argument");\
}\
\
static constexpr std::optional<enum_type> from_string(std::string_view name) noexcept {\
[[maybe_unused]] static constexpr std::optional<enum_type> from_string(std::string_view name) noexcept {\
for ( std::size_t i = 0; i < size; ++i) {\
if ( name == names[i] ) {\
return values[i];\
@@ -291,52 +289,49 @@ namespace enum_hpp::detail
}\
return std::nullopt;\
}\
static constexpr enum_type from_string_or_default(std::string_view name, enum_type def) noexcept {\
[[maybe_unused]] static constexpr enum_type from_string_or_default(std::string_view name, enum_type def) noexcept {\
if ( auto e = from_string(name) ) {\
return *e;\
}\
return def;\
}\
static enum_type from_string_or_throw(std::string_view name) {\
[[maybe_unused]] static enum_type from_string_or_throw(std::string_view name) {\
if ( auto e = from_string(name) ) {\
return *e;\
}\
::enum_hpp::detail::throw_exception_with(#Enum "_traits::from_string_or_throw(): invalid argument");\
}\
\
static constexpr std::optional<std::size_t> to_index(enum_type e) noexcept {\
[[maybe_unused]] static constexpr std::optional<std::size_t> to_index(enum_type e) noexcept {\
switch ( e ) {\
ENUM_HPP_GENERATE_VALUE_TO_INDEX_CASES(Enum, Fields)\
default: return std::nullopt;\
}\
}\
\
static constexpr std::size_t to_index_or_invalid(enum_type e) noexcept {\
[[maybe_unused]] static constexpr std::size_t to_index_or_invalid(enum_type e) noexcept {\
if ( auto i = to_index(e) ) {\
return *i;\
}\
return ::enum_hpp::invalid_index;\
}\
static std::size_t to_index_or_throw(enum_type e) {\
[[maybe_unused]] static std::size_t to_index_or_throw(enum_type e) {\
if ( auto i = to_index(e) ) {\
return *i;\
}\
::enum_hpp::detail::throw_exception_with(#Enum "_traits::to_index_or_throw(): invalid argument");\
}\
\
static constexpr std::optional<enum_type> from_index(std::size_t index) noexcept {\
[[maybe_unused]] static constexpr std::optional<enum_type> from_index(std::size_t index) noexcept {\
if ( index < size ) {\
return values[index];\
}\
return std::nullopt;\
}\
static constexpr enum_type from_index_or_default(std::size_t index, enum_type def) noexcept {\
[[maybe_unused]] static constexpr enum_type from_index_or_default(std::size_t index, enum_type def) noexcept {\
if ( auto e = from_index(index) ) {\
return *e;\
}\
return def;\
}\
static enum_type from_index_or_throw(std::size_t index) {\
[[maybe_unused]] static enum_type from_index_or_throw(std::size_t index) {\
if ( auto e = from_index(index) ) {\
return *e;\
}\

View File

@@ -58,7 +58,7 @@ namespace enum_hpp::bitflags
constexpr bitflags& toggle(bitflags flags) noexcept {
flags_ ^= flags.flags_;
return *this;
};
}
constexpr bitflags& clear(bitflags flags) noexcept {
flags_ &= ~flags.flags_;

View File

@@ -25,7 +25,10 @@ target_compile_options(${PROJECT_NAME}
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Werror -Wall -Wextra -Wpedantic>)
$<$<CXX_COMPILER_ID:GNU>:
-Werror -Wall -Wextra -Wpedantic>
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Werror -Weverything -Wconversion>)
add_test(${PROJECT_NAME} ${PROJECT_NAME})