diff --git a/CMakePresets.json b/CMakePresets.json index c2c69be..fb9a2c7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -93,6 +93,13 @@ "release-base" ] }, + { + "name": "gcc_debug", + "inherits": [ + "gcc-base", + "debug-base" + ] + }, { "name": "gcc_release", "inherits": [ diff --git a/README.md b/README.md index 7d12f55..e2cca89 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,8 @@ ctest --test-dir out/build/gcc_release ``` ## presets -- `gcc_release`, `clang_release`, `msvc_release` -- windows only: `clang_debug`, `msvc_debug` +- `gcc_debug`, `gcc_release`, `clang_debug`, `clang_release` +- windows only: `msvc_debug`, `msvc_release` # using cth in another project building installs the package into `out/install/` (target `cth_package`), point `cth_ROOT` there: diff --git a/cth/incl/cth/constants.hpp b/cth/incl/cth/constants.hpp index 708f950..451a7d3 100644 --- a/cth/incl/cth/constants.hpp +++ b/cth/incl/cth/constants.hpp @@ -14,6 +14,13 @@ #ifndef CTH_RELEASE_MODE #define CTH_RELEASE_MODE #endif + +#else +#ifndef CTH_RELEASE_MODE +#ifndef CTH_DEBUG_MODE +#define CTH_DEBUG_MODE +#endif +#endif #endif #ifdef CTH_DEBUG_MODE @@ -22,12 +29,6 @@ #endif #endif -#ifndef CTH_DEBUG_MODE -#ifndef CTH_RELEASE_MODE -#error "Neither CTH_DEBUG_MODE nor CTH_RELEASE_MODE is defined." -#endif -#endif - #ifdef CTH_DEBUG_MODE #define CTH_DEBUG_IMPL #define CTH_DEBUG_INLINE_IMPL(code) { code } diff --git a/cth/incl/cth/data/poly_vector.hpp b/cth/incl/cth/data/poly_vector.hpp index 60ddfe3..f55239d 100644 --- a/cth/incl/cth/data/poly_vector.hpp +++ b/cth/incl/cth/data/poly_vector.hpp @@ -69,6 +69,9 @@ class raw_poly_vector { offset += typeSizes[i] * sizes[i]; } + free(); + _begins = {}; + if(offset == 0) return; diff --git a/cth/incl/cth/data/union_find.hpp b/cth/incl/cth/data/union_find.hpp index 20907d3..91ff5c4 100644 --- a/cth/incl/cth/data/union_find.hpp +++ b/cth/incl/cth/data/union_find.hpp @@ -106,13 +106,13 @@ class union_find { auto& rootSize = size_ref(root); for(auto& node : group) { - auto& p = parent(node); + auto const nodeRoot = find(node); - if(p == root) + if(nodeRoot == root) continue; - rootSize++; - p = root; + rootSize += size_ref(nodeRoot); + parent(nodeRoot) = root; } } diff --git a/cth/incl/cth/enums.hpp b/cth/incl/cth/enums.hpp index 8694024..85fa791 100644 --- a/cth/incl/cth/enums.hpp +++ b/cth/incl/cth/enums.hpp @@ -3,7 +3,7 @@ #include namespace cth::en { -constexpr size_t flag_val(size_t id) { return 1 << id; } +constexpr size_t flag_val(size_t id) { return size_t{1} << id; } } #define CTH_GEN_ENUM_DEREF_OVERLOAD(EnumType) \ diff --git a/cth/incl/cth/exception.hpp b/cth/incl/cth/exception.hpp index 0014301..9bf8c5a 100644 --- a/cth/incl/cth/exception.hpp +++ b/cth/incl/cth/exception.hpp @@ -126,43 +126,31 @@ class default_exception : public std::exception { [[nodiscard]] std::string trace_string() const noexcept { std::string str = "STACKTRACE:\n"; - std::for_each( - _trace.begin(), - _trace.end() - 2, - [&](auto const& entry) { - std::filesystem::path const path{entry.source_file()}; - str += std::format( - "\t{2} : {0}({1})\n", - path.filename().string(), - entry.source_line(), - entry.description() - ); - } - ); - std::for_each( - _trace.begin(), - _trace.end() - 2, - [&](auto const& entry) { - std::filesystem::path const path{entry.source_file()}; - str += std::format( - "\t{2} : {0}({1})\n", - path.filename().string(), - entry.source_line(), - entry.description() - ); - } - ); + for(auto const& entry : _trace) { + if(entry.description().empty()) + continue; + + std::filesystem::path const path{entry.source_file()}; + + str += std::format( + "\t{2} : {0}({1})\n", + path.filename().string(), + entry.source_line(), + entry.description() + ); + } + return str; } private: Severity _severity; std::string _msg; - std::string _details{}; + std::string _details; std::source_location _sourceLocation; std::stacktrace _trace; - std::string _what{}; + std::string _what; public: [[nodiscard]] cxpr Severity severity() const noexcept { return _severity; } diff --git a/cth/incl/cth/ptr/move_ptr.hpp b/cth/incl/cth/ptr/move_ptr.hpp index 3eb8ad7..90521cf 100644 --- a/cth/incl/cth/ptr/move_ptr.hpp +++ b/cth/incl/cth/ptr/move_ptr.hpp @@ -31,7 +31,7 @@ struct move_ptr { */ [[nodiscard]] constexpr T* release(this move_ptr& s) noexcept { return std::exchange(s._ptr, nullptr); } [[nodiscard]] constexpr auto operator->(this auto& s) noexcept { return s._ptr; } - [[nodiscard]] constexpr auto operator*(this auto& s) noexcept { return *s._ptr; } + [[nodiscard]] constexpr decltype(auto) operator*(this auto& s) noexcept { return *s._ptr; } [[nodiscard]] constexpr operator bool(this move_ptr const& s) { return static_cast(s._ptr); } constexpr move_ptr(move_ptr const& other) = default; diff --git a/cth/tests/src/data/union_find_test.cpp b/cth/tests/src/data/union_find_test.cpp index aeab51d..2c9b24e 100644 --- a/cth/tests/src/data/union_find_test.cpp +++ b/cth/tests/src/data/union_find_test.cpp @@ -98,5 +98,15 @@ DATA_TEST(union_find, all) { EXPECT_TRUE(std::ranges::equal(find.all(), expectedGroups)); } +DATA_TEST(union_find, merge_overlapping_groups) { + union_find find(4); + + find.merge({0, 1}); + find.merge({2, 3}); + find.merge({1, 3}); + + EXPECT_EQ(find.all_of(0), (std::vector{0, 1, 2, 3})); +} + } diff --git a/lib/cth_cmake b/lib/cth_cmake index af0e178..c7e1056 160000 --- a/lib/cth_cmake +++ b/lib/cth_cmake @@ -1 +1 @@ -Subproject commit af0e178cab6f455c17bc744ef7c52fcffd9d9af6 +Subproject commit c7e10561071356dc92cd37df2b47a87effff4a7a