Skip to content

Instantly share code, notes, and snippets.

View jmal0's full-sized avatar

John Maloney jmal0

View GitHub Profile
@jmal0
jmal0 / Aligned_ptr.h
Created June 25, 2018 02:55
C++ aligned pointer wrapper
#include <cstddef>
#include <cstdlib>
#include <memory>
//! @brief Wraps compiler specific builtin alignment assumptions
template <std::size_t alignment, typename T>
T* assume_aligned(T* ptr)
{
#if defined(__INTEL_COMPILER)
// ICPC defines __GNUC__ so check this first
@jmal0
jmal0 / example.hpp
Created April 18, 2018 02:34
append to variadic template
#include <template_append.hpp>
#include <tuple>
#define WITH_INT
#define WITH_DOUBLE
using type0 = std::tuple<>;
#ifdef WITH_INT
using type1 = JMAL::template_append<int, type0>::type;
#else
@jmal0
jmal0 / generic_metrics.hpp
Last active April 13, 2018 20:43
Generic metrics template metaprogram
#ifndef _GENERIC_METRICS_H
#define _GENERIC_METRICS_H
#include <cstddef>
#include <tuple>
#include <utility>
#if !__cpp_lib_tuples_by_type
static_assert(false, "Missing required C++14 feature");
#endif
@jmal0
jmal0 / abstract_factory_test.cpp
Last active October 8, 2017 01:44
C++ static Abstract_factory as a CRTP
#include <initializer_list>
#include <iostream>
#include <memory>
#include <string>
// Example base type
class Base
{
public:
Base(const double a, const double b) :