Skip to content

Commit

Permalink
pre-v1.0g-update
Browse files Browse the repository at this point in the history
  • Loading branch information
dakka committed Apr 5, 2024
1 parent 46dff13 commit 715848d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#
# Lightweight header-only C++20 enum reflection
#
# Parts based on magic_enum <https://github.com/Neargye/magic_enum>
# Copyright (c) 2019 - 2024 Daniil Goncharov <[email protected]>.
#
# Licensed under the MIT License <http://opensource.org/licenses/MIT>.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -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
Expand All @@ -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
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)
endif()
if(BUILD_UNITTESTS)
target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain)
endif()
Expand Down
7 changes: 2 additions & 5 deletions examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
//
// Lightweight header-only C++20 enum reflection
//
// Parts based on magic_enum <https://github.com/Neargye/magic_enum>
// Copyright (c) 2019 - 2024 Daniil Goncharov <[email protected]>.
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -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<component>::for_each([](component val, int other, int& tot)
Expand Down Expand Up @@ -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<numbers&> er("one|three|four|eight"sv, true);
//enum_bitset<numbers&> er("one|three|four|eight"sv, true);

for (const auto pp : iterator_adaptor<numbers>())
std::cout << static_cast<int>(std::get<0>(pp)) << '\n';
Expand Down
5 changes: 1 addition & 4 deletions examples/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
//
// Lightweight header-only C++20 enum reflection
//
// Parts based on magic_enum <https://github.com/Neargye/magic_enum>
// Copyright (c) 2019 - 2024 Daniil Goncharov <[email protected]>.
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -263,7 +260,7 @@ TEST_CASE("for_each")
TEST_CASE("enum_bitset")
{
enum_bitset<numbers> eb;
enum_bitset<numbers&> ebr;
//enum_bitset<numbers&> ebr;
eb.set_all<numbers::zero,numbers::two,numbers::five,numbers::nine>();
REQUIRE(eb.test_all<numbers::zero,numbers::two,numbers::five,numbers::nine>());
eb.reset<numbers::FIVE>(); // use alias
Expand Down
8 changes: 4 additions & 4 deletions include/fix8/conjure_enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> int_to_enum(int value) noexcept
{
Expand Down Expand Up @@ -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)) {}

Expand Down Expand Up @@ -456,7 +456,7 @@ class enum_bitset
constexpr void reset_all() noexcept { (reset<comp>(),...); }
template<typename... I>
requires(std::is_integral_v<I> && ...)
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)); }
Expand Down

0 comments on commit 715848d

Please sign in to comment.