Skip to content

Instantly share code, notes, and snippets.

@zno5
zno5 / MySingleton.cpp
Created November 4, 2016 15:30
singleton class using std::call_once
#include <mutex>
class MySingleton {
public:
static MySingleton * GetInstance() {
std::call_once(
m_flag,
[] () { m_instance = new MySingleton(); }
);
@zno5
zno5 / map_emplace_example.cpp
Created March 27, 2017 05:10
map, emplace w/o creating a object temporarily
struct Item {
int m_val1;
int m_val2;
Item (int val1, int val2) {
m_val1 = val1;
m_val2 = val2;
}
};
@zno5
zno5 / count_param_pack.cpp
Created August 23, 2017 07:24
count the number of arguments
template <typename ... Ts>
struct ParamPack;
template <>
struct ParamPack<> {
static constexpr size_t count = 0;
};
template <typename T, typename ... Ts>
struct ParamPack<T, Ts...> {
@zno5
zno5 / ScopeGuard.h
Created September 18, 2017 06:07
Call a function automatically on scope exit
/*
Usage:
class Test;
bool Finalize ();
bool Finalize (int i);
bool Finalize (int i, int j);
{