Skip to content

Instantly share code, notes, and snippets.

@en4bz
en4bz / rwlock.cpp
Last active July 16, 2018 00:57
Reader Writer Lock
#include <unistd.h>
#include <limits.h>
#include <linux/futex.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <errno.h>
#include <cstdio>
#include <cstdlib>
#include <atomic>
@en4bz
en4bz / format.cpp
Last active February 21, 2017 02:37
sprintf with C++ variadic templates
#include <iostream>
#include <sstream>
#include <tuple>
template<class Tuple, std::size_t N>
struct TuplePrinter {
static void print(const std::string& fmt, std::ostream& os, const Tuple& t) {
const size_t idx = fmt.find_last_of('%');
TuplePrinter<Tuple, N-1>::print(std::string(fmt, 0, idx), os,t);
os << std::get<N-1>(t) << std::string(fmt, idx + 1);