C++
Links
cmake
Start cmake folder
CMAKE_FOLDER=build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -S . -B $CMAKE_FOLDER
Build
CMAKE_FOLDER=build
cmake --build $CMAKE_FOLDER -j "$(nproc)"
--build <path> project binary directory to be built
nproc print the number of processing units available
What to use

cppcheck
apt install cppcheck
cppcheck --enable=style path/to/file.c
cppcheck --enable=all path/to/file.c
Pointers
#include <iostream>
#include <memory>
int main() {
int x = 10;
int* raw = &x;
std::cout << *raw << '\n';
auto unique = std::make_unique<int>(20);
std::cout << *unique << '\n';
auto unique2 = std::move(unique);
std::cout << *unique2 << '\n';
auto shared1 = std::make_shared<int>(30);
auto shared2 = shared1;
std::cout << *shared1 << '\n';
std::cout << shared1.use_count() << '\n';
std::weak_ptr<int> weak = shared1;
if (auto locked = weak.lock()) {
std::cout << *locked << '\n';
}
shared1.reset();
std::cout << shared2.use_count() << '\n';
shared2.reset();
std::cout << std::boolalpha << weak.expired() << '\n';
}
Rule of 3, 5 and 0
#include <algorithm>
#include <iostream>
#include <memory>
class RuleOf3 {
int* data;
public:
explicit RuleOf3(int value) : data(new int(value)) {}
~RuleOf3() { delete data; }
RuleOf3(const RuleOf3& other)
: data(new int(*other.data)) {}
RuleOf3& operator=(const RuleOf3& other) {
if (this != &other)
*data = *other.data;
return *this;
}
};
class RuleOf5 {
int* data;
public:
explicit RuleOf5(int value) : data(new int(value)) {}
~RuleOf5() { delete data; }
RuleOf5(const RuleOf5& other)
: data(new int(*other.data)) {}
RuleOf5& operator=(const RuleOf5& other) {
if (this != &other)
*data = *other.data;
return *this;
}
RuleOf5(RuleOf5&& other) noexcept : data(other.data) {
other.data = nullptr;
}
RuleOf5& operator=(RuleOf5&& other) noexcept {
if (this != &other) {
delete data;
data = other.data;
other.data = nullptr;
}
return *this;
}
};
class RuleOf0 {
std::unique_ptr<int> data;
public:
explicit RuleOf0(int value)
: data(std::make_unique<int>(value)) {}
};