Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ferrite++ 🦀➡️🛡️

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++.

Features

Synchronous / Single-Threaded

  • 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-like RefCell equivalent 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.

Asynchronous (C++20 Coroutines)

  • 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 using std::variant to prevent writer starvation.

Installation & Usage

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)

Example (Arc)

#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";
}

License

Distributed under the MIT License. See LICENSE for more information.

About

Ferrite++ brings Rust's robust ownership, memory safety, and concurrency primitives into Modern C++20.

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages