Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@
"release-base"
]
},
{
"name": "gcc_debug",
"inherits": [
"gcc-base",
"debug-base"
]
},
{
"name": "gcc_release",
"inherits": [
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<preset>` (target `cth_package`), point `cth_ROOT` there:
Expand Down
13 changes: 7 additions & 6 deletions cth/incl/cth/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions cth/incl/cth/data/poly_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class raw_poly_vector {
offset += typeSizes[i] * sizes[i];
}

free();
_begins = {};

if(offset == 0)
return;

Expand Down
8 changes: 4 additions & 4 deletions cth/incl/cth/data/union_find.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion cth/incl/cth/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <type_traits>

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) \
Expand Down
44 changes: 16 additions & 28 deletions cth/incl/cth/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion cth/incl/cth/ptr/move_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(s._ptr); }

constexpr move_ptr(move_ptr const& other) = default;
Expand Down
10 changes: 10 additions & 0 deletions cth/tests/src/data/union_find_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>{0, 1, 2, 3}));
}


}
2 changes: 1 addition & 1 deletion lib/cth_cmake
Submodule cth_cmake updated 1 files
+2 −2 toolchain.cmake
Loading