Skip to content

Instantly share code, notes, and snippets.

View vladiant's full-sized avatar
🏠
Working from home

Vladislav Antonov vladiant

🏠
Working from home
View GitHub Profile
@vladiant
vladiant / 10_std_apply_generic.cpp
Created November 4, 2025 19:23
C++ tuple iteration 2
#include <iostream>
#include <tuple>
// basic printing
template <typename TupleT, std::size_t... Is>
void printTupleImp(const TupleT& tp, std::index_sequence<Is...>) {
size_t index = 0;
auto printElem = [&index](const auto& x) {
if (index++ > 0)
std::cout << ", ";
@vladiant
vladiant / 1_tuple_iter.cpp
Created November 4, 2025 19:15
C++ tuple iteration 1
#include <iostream>
#include <tuple>
template <typename T>
void printElem(const T& x) {
std::cout << x << ',';
};
template <typename TupleT, std::size_t... Is>
void printTupleManual(const TupleT& tp) {
@vladiant
vladiant / ReadMe.md
Last active September 12, 2025 20:17
C++ contracts

Contracts

Main features

contract_assert replaces assert

  • Unlike assert, contract_assert is a proper keyword

Four build options: the evaluation semantics

  • ignore – do not check the assertion;
  • enforce — check the assertion; if the check fails, print a message and terminate (the default behaviour);
@vladiant
vladiant / adr.txt
Created April 20, 2025 06:46
Architecture Decision Records
Why Documenting Architecture Decisions Matters
1. A Single Source of Truth
2. Better Onboarding and Cross-Team Collaboration
3. Encourage Thoughtful, Data-Driven Decisions
4. Simplify Architecture Evolution
ADRs are meant to capture key decisions that have long-term implications for your system or organization. If a decision introduces a new dependency, alters fundamental data flows, or significantly affects architecture and team processes, it likely requires an ADR.
On the other hand, minor decisions - like tweaking a library version or refactoring a single function usually don’t need an official record.
@vladiant
vladiant / crtp.cpp
Created April 8, 2025 18:10
C++26: variadic friends
// The base class
template<class Crtp, class MsgT>
class Receiver {
void receive(MsgT) {
static_cast<Crtp*>(this)->private_ += 1;
}
};
// The derived class
@vladiant
vladiant / template_metaprogramming_helpers.cpp
Created April 8, 2025 18:00
Tiny C++ template metaprogramming helpers
// https://vawale.github.io/posts/template_metaprogramming_helpers/
template<typename... Args>
consteval auto count() {
return sizeof...(Args);
}
template<template <typename T> typename Predicate, typename... Args>
consteval auto count_if() -> size_t {
return (0 + ... + Predicate<Args>{}());
@vladiant
vladiant / Makefile
Created April 6, 2025 19:38
Simple C++ Makefile
##################################################
## ##
## Simple Universal C/C++ Makefile v2.0 ##
## ##
##################################################
##################################################
## GLOBAL CONFIGURATION ##
##################################################
@vladiant
vladiant / atomic_thread_fence.cpp
Last active March 2, 2025 07:26
C++ Threads Memory Order
#include <atomic>
#include <string>
#include <thread>
#include <iostream>
// Global
std::string computation(int a){
return std::to_string(a);
}