Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Forbes en4bz

  • VMWare Inc.
  • Austin, Texas
View GitHub Profile
@en4bz
en4bz / rwlock.cpp
Last active Jul 16, 2018
Reader Writer Lock
View rwlock.cpp
#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 Feb 21, 2017
sprintf with C++ variadic templates
View format.cpp
#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);