This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
template<class L> | |
struct Left { | |
L const value; | |
}; | |
template<class R> | |
struct Right { | |
R const value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program | |
#include <iostream> | |
#include <string> | |
struct Dual { | |
float real; | |
float img; | |
Dual(float x, float y=0) | |
:real{x}, img{y} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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...)>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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...)>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |