Ferrite++ brings Rust's robust ownership, memory safety, and concurrency primitives into Modern C++20.
Named after ferrite materials—strong and resilient, yet brittle under non-ideal conditions—this library highlights the beauty and hazards of systems programming in C++.
Arc<T>— Atomic reference-counted shared ownership (read-only data by default, with shallow & deep cloning).Rc<T>— Single-threaded reference-counted shared ownership with a single heap allocation (ControlBlock).Bor<T>,Imut<T>,Mut<T>— Rust-likeRefCellequivalent providing interior mutability with runtime borrow checking.Mx<T>— RAII guard and closure-based synchronization for thread-safe mutations.Rw<T>— Reader-Writer lock supporting shared reads and exclusive writes.
ferrite::async::Mx<T>— Asynchronous coroutine mutex with a fair waiting queue and local resumption to prevent stack overflows.ferrite::async::Rw<T>— Asynchronous coroutine Reader-Writer lock usingstd::variantto prevent writer starvation.
Since Ferrite++ is a header-only library, you can simply copy the include/ferrite folder into your project, or include it via CMake FetchContent:
include(FetchContent)
FetchContent_Declare(
ferrite_cpp
GIT_REPOSITORY https://github.com/bandicm/ferrite_cpp.git
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(ferrite_cpp)
target_link_libraries(your_target PRIVATE ferrite::ferrite)#include <iostream>
#include "ferrite/arc.hpp"
int main() {
ferrite::Arc<int> a(42);
ferrite::Arc<int> b = a; // Shared ownership
std::cout << "Reference count: " << a.ref_count() << "\n";
std::cout << "Value: " << *a << "\n";
}Distributed under the MIT License. See LICENSE for more information.