Skip to content

Instantly share code, notes, and snippets.

View olibre's full-sized avatar
🦆
Empowering self-governance

O. Libre olibre

🦆
Empowering self-governance
View GitHub Profile
@odeblic
odeblic / smart_dtor.cpp
Last active October 7, 2018 21:10
Smart destructor
#include <iostream>
#include <memory>
struct Base
{
~Base()
{
std::cout << "~Base()" << std::endl;
}
};
@olibre
olibre / smart_dtor.cpp
Last active October 7, 2018 21:10 — forked from odeblic/smart_dtor.cpp
Smart destructor
/*
* Original work: https://gist.github.com/odeblic/fa54037bf4d764a5dc02735cb4bd79f3
* Inspired from: https://youtu.be/ZiNGWHg5Z-o
*
* Compile
*
* $ g++ -Wall -Wextra smart_dtor.cpp
*
* Run
*
@hutorny
hutorny / enumnames.hpp
Created January 21, 2017 18:05
Zero-dependency allocation-free mapping enum values to names for C++11
/** zero-dependency allocation-free mapping enum values to names */
namespace enumnames {
typedef const char* (*name)();
bool match(const char*, const char*) noexcept; /* to be provided by the user */
template<typename T, T K, name V>
struct tuple {
typedef T key_t;
static constexpr T key = K;
@dscharrer
dscharrer / infix_operator.cpp
Created June 7, 2012 07:38
The proper way to call std::swap
#include <type_traits>
namespace detail {
// No need to give up constexpr for std::forward
template <class T>
constexpr T && forward(typename std::remove_reference<T>::type & t) noexcept {
return static_cast<T &&>(t);
}