Skip to content

Instantly share code, notes, and snippets.

@adamski
adamski / Callable.hpp
Created September 14, 2020 15:59
Convert a std::function to a function pointer and context pointer, for use with C API callbacks.
/**
* Usage:
* ```
* std::function<void(int32)> callback; // This should be stored as e.g. class member
* ...
* addInt32Callback (wrapCallable<int32>(callback), &callback);
* ```
* @tparam T
* @tparam Callable
* @return function pointer
@alexandreelise
alexandreelise / README.md
Last active October 25, 2024 00:12
Install gcc 9 on Ubuntu LTS 12.04,14.04,16.04 and 18.04

Hi! gcc users

There is good news for you. I made a new repository with a single Dockerfile to build every combinations of versions of Ubuntu LTS and gcc you like

Find out more on https://github.com/alexandreelise/install-gcc

@fenbf
fenbf / sfinae_tostring_ex.cpp
Created February 9, 2016 20:33
C++ SFINAE example: how to detect if a class contains ToString method
// SFINAE, enable_if example
// based on http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
#include <iostream>
#include <type_traits>
class ClassWithToString
{
public:
@AndrewScheidecker
AndrewScheidecker / gist:930f4a6e0966b8421806
Created September 4, 2014 12:43
A stupid C++ trick for defining structs with metadata (serializers, printers, etc) without redundant declarations of members
#include <iostream>
#include <vector>
#include <string>
using std::string;
/*
These macros define a struct with an implicitly defined Show function that visits each member.
The trick is that a typedef is split between each STRUCT_MEMBER instance and the preceding macro,
which allows it to define an empty struct type that identifies the following struct member, while also
knowing the struct type that the preceding macro is using to identify the current member.