Skip to content

Instantly share code, notes, and snippets.

View nikhedonia's full-sized avatar
💭
actively open-sourcing

Gaetano Checinski nikhedonia

💭
actively open-sourcing
View GitHub Profile
@nikhedonia
nikhedonia / EitherAsmAnalysis.cpp
Created May 16, 2017 11:39
analysing Assembly generated by Eithers
#include <type_traits>
template<class L>
struct Left {
L const value;
};
template<class R>
struct Right {
R const value;
@nikhedonia
nikhedonia / Duals.cpp
Created February 23, 2017 20:01
example showing the beauty of duals
// Example program
#include <iostream>
#include <string>
struct Dual {
float real;
float img;
Dual(float x, float y=0)
:real{x}, img{y}
#include<functional>
template<class T>
struct AsFunction
: public AsFunction<decltype(&T::operator())>
{};
template<class ReturnType, class... Args>
struct AsFunction<ReturnType(Args...)> {
using type = std::function<ReturnType(Args...)>;
#include<functional>
template<class T>
struct AsFunction
: public AsFunction<decltype(&T::operator())>
{};
template<class ReturnType, class... Args>
struct AsFunction<ReturnType(Args...)> {
using type = std::function<ReturnType(Args...)>;
#include<vector>
#include<iostream>
template<class T>
struct Matrix {
Matrix(std::size_t n=1, std::size_t m=1)
: n{n}, m{m}, data(n*m)
{}
Matrix(std::size_t n, std::size_t m, std::vector<T> const& data)
#include<iostream>
#include<vector>
#include<string>
#include<set>
auto numberOfUniqueChars(std::string const& str) {
std::set<char> s;
for(auto c : str) {
s.insert(c);
}
// Type Erasure
// https://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil
// https://akrzemi1.wordpress.com/2013/11/18/type-erasure-part-i/
#include<memory>
#include<iostream>
struct Printable {
//SFINAE - Substitution-Failure-Is-Not-An-Error
template<bool condition, class T>
struct enable_if {
using type = T;
};
template<class T>
struct enable_if<false,T>
@nikhedonia
nikhedonia / Fib.cpp
Last active August 31, 2016 18:53
Gist created by https://fiddle.jyt.io
// Fibonacci
//press play and call a function from the terminal on the right hand side
#include<math.h>
#include<vector>
#include<functional>
#include<tuple>
#include<algorithm>
// Fibonacci
#include<math.h>
#include<vector>
// This slow machine will barely be able to compute Fib1(30)
// O(n!)
constexpr auto FibR(size_t n) {