diff --git a/CMakeLists.txt b/CMakeLists.txt index ce3b3928..6eb4423d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,6 @@ # # Lightweight header-only C++20 enum reflection # -# Parts based on magic_enum -# Copyright (c) 2019 - 2024 Daniil Goncharov . -# # Licensed under the MIT License . # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -37,10 +34,16 @@ project (conjure_enum VERSION 1.0.0 ) +# to disable warnings: +# cmake -DBUILD_ALL_WARNINGS=false .. +option(BUILD_ALL_WARNINGS "enable building with all warnings" true) +message("-- Build with all warnings : ${BUILD_ALL_WARNINGS}") + # to disable building unit tests: # cmake -DBUILD_UNITTESTS=false .. option(BUILD_UNITTESTS "enable building unit tests" true) message("-- Build unit tests: ${BUILD_UNITTESTS}") + if(BUILD_UNITTESTS) include(FetchContent) FetchContent_Declare(Catch2 @@ -62,6 +65,11 @@ 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 examples) + if(BUILD_ALL_WARNINGS) + target_compile_options(${target} PRIVATE + $<$:/W4> + $<$>:-Wall -Wextra -Wpedantic>) + endif() if(BUILD_UNITTESTS) target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain) endif() diff --git a/examples/example.cpp b/examples/example.cpp index 1f537998..1c190b8b 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -7,9 +7,6 @@ // // Lightweight header-only C++20 enum reflection // -// Parts based on magic_enum -// Copyright (c) 2019 - 2024 Daniil Goncharov . -// // Licensed under the MIT License . // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -71,7 +68,7 @@ const std::string demangle() noexcept return typeid(T).name(); } -int main(int argc, char *argv[]) +int main(void) { int total{}; auto myfunc { conjure_enum::for_each([](component val, int other, int& tot) @@ -197,7 +194,7 @@ int main(int argc, char *argv[]) const foo bar; ek.for_each(std::bind(&foo::printer, &bar, std::placeholders::_1, 10)); ek.for_each(&foo::printer, &bar, 10); - enum_bitset er("one|three|four|eight"sv, true); + //enum_bitset er("one|three|four|eight"sv, true); for (const auto pp : iterator_adaptor()) std::cout << static_cast(std::get<0>(pp)) << '\n'; diff --git a/examples/unittests.cpp b/examples/unittests.cpp index 54124752..027a40a1 100644 --- a/examples/unittests.cpp +++ b/examples/unittests.cpp @@ -7,9 +7,6 @@ // // Lightweight header-only C++20 enum reflection // -// Parts based on magic_enum -// Copyright (c) 2019 - 2024 Daniil Goncharov . -// // Licensed under the MIT License . // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -263,7 +260,7 @@ TEST_CASE("for_each") TEST_CASE("enum_bitset") { enum_bitset eb; - enum_bitset ebr; + //enum_bitset ebr; eb.set_all(); REQUIRE(eb.test_all()); eb.reset(); // use alias diff --git a/include/fix8/conjure_enum.hpp b/include/fix8/conjure_enum.hpp index 531a6106..ab01bc06 100644 --- a/include/fix8/conjure_enum.hpp +++ b/include/fix8/conjure_enum.hpp @@ -304,8 +304,8 @@ class conjure_enum final static constexpr auto cend() noexcept { return entries.cend(); } static constexpr auto crbegin() noexcept { return entries.crbegin(); } static constexpr auto crend() noexcept { return entries.crend(); } - static constexpr auto front() noexcept { return *entries.cbegin(); } - static constexpr auto back() noexcept { return *std::prev(entries.cend()); } + static constexpr auto front() noexcept { return *cbegin(); } + static constexpr auto back() noexcept { return *std::prev(cend()); } static constexpr std::optional int_to_enum(int value) noexcept { @@ -395,7 +395,7 @@ class enum_bitset U _present{}; public: - constexpr enum_bitset(U bits) noexcept : _present(bits) {} + explicit constexpr enum_bitset(U bits) noexcept : _present(bits) {} constexpr enum_bitset(std::string_view from, bool anyscope=false, char sep='|', bool ignore_errors=true) : _present(factory(from, anyscope, sep, ignore_errors)) {} @@ -456,7 +456,7 @@ class enum_bitset constexpr void reset_all() noexcept { (reset(),...); } template requires(std::is_integral_v && ...) - constexpr void reset_all(I...comp) noexcept { (reset(comp),...); }; + constexpr void reset_all(I...comp) noexcept { (reset(comp),...); } constexpr bool test(U pos) const noexcept { return _present & (1 << pos); } constexpr bool test(T what) const noexcept { return test(to_underlying(what)); }