diff --git a/CMakeLists.txt b/CMakeLists.txt index 22db6470..6a0c2398 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,11 @@ project (conjure_enum VERSION 1.0.0 ) +# to enable conservative C++20 build: +# cmake -DBUILD_CONSRVCPP20=true .. +option(BUILD_CONSRVCPP20 "enable conservative C++20 build" false) +message("-- Build conservative C++20: ${BUILD_CONSRVCPP20}") + # to disable warnings: # cmake -DBUILD_ALL_WARNINGS=false .. option(BUILD_ALL_WARNINGS "enable building with all warnings" true) @@ -65,6 +70,9 @@ foreach(x IN LISTS files) add_executable(${target} examples/${x}) set_target_properties(${target} PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED true) target_include_directories(${target} PRIVATE include) + if (BUILD_CONSRVCPP20) + target_compile_definitions(${target} PRIVATE BUILD_CONSRVCPP20) + endif() if(BUILD_ALL_WARNINGS) target_compile_options(${target} PRIVATE $<$:/W4> diff --git a/include/fix8/conjure_enum.hpp b/include/fix8/conjure_enum.hpp index c4ee4fcc..5546a658 100644 --- a/include/fix8/conjure_enum.hpp +++ b/include/fix8/conjure_enum.hpp @@ -192,7 +192,7 @@ class conjure_enum final return false; } -#if defined(__clang__) && defined(__apple_build_version__) // std::count_if not constexpr in xcode/clang +#if defined BUILD_CONSRVCPP20 template static constexpr auto count_if_constexpr(const bool (&valid)[N]) noexcept { @@ -207,7 +207,7 @@ class conjure_enum final template static constexpr auto _values(std::index_sequence) noexcept { -#if defined(__clang__) && defined(__apple_build_version__) +#if defined BUILD_CONSRVCPP20 constexpr bool valid[sizeof...(I)] { _is_valid(enum_min_value + I)>()... }; constexpr auto num_valid { count_if_constexpr(valid) }; #else