Skip to content

Instantly share code, notes, and snippets.

#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
template< class F, class G > struct AccumRight {
F f = F();
G g = G();
constexpr AccumRight() { }
@splinterofchaos
splinterofchaos / monad-parser.cpp
Created November 19, 2012 17:32
Monadic parsing in C++
#include <memory>
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
@splinterofchaos
splinterofchaos / gist:4055136
Created November 11, 2012 14:56
Transitivity and Associativity.
#include <utility>
using std::forward;
using std::declval;
using std::move;
template< class F, class X >
struct Part {
F f;
X x;
@splinterofchaos
splinterofchaos / constructChainable.cpp
Created November 10, 2012 04:47
Construct Chainable -- A demonstration of a left-associative type constructor.
#include <utility>
#include <iostream>
// http://en.cppreference.com/w/cpp/types/decay
template< class X >
using Decay = typename std::decay<X>::type;
// ConstructBinary<T>(X,Y) = T<X,Y>
template< template<class...> class X >
struct ConstructBinary {
@splinterofchaos
splinterofchaos / binary-function.cpp
Created November 6, 2012 13:14
Rethinking std::binary_function
#include <memory>
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <iterator>
template<class...> struct Part;
.file "func-effic.cpp"
# GNU C++ (Ubuntu/Linaro 4.7.2-4precise1) version 4.7.2 (x86_64-linux-gnu)
# compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -imultiarch x86_64-linux-gnu -D_GNU_SOURCE
# func-effic.cpp -mtune=generic -march=x86-64 -O4 -std=c++11 -fverbose-asm
# -fstack-protector
# options enabled: -fasynchronous-unwind-tables -fauto-inc-dec
# -fbranch-count-reg -fcaller-saves -fcombine-stack-adjustments -fcommon
# -fcompare-elim -fcprop-registers -fcrossjumping -fcse-follow-jumps
#include <memory>
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
#include <memory>
#include <iostream>
#include <utility>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
@splinterofchaos
splinterofchaos / fmap.cpp
Created October 26, 2012 18:02
Fmap in C++
#include <memory>
#include <utility>
#include <iostream>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
template< class X >
@splinterofchaos
splinterofchaos / pure-test.cpp
Created July 18, 2012 14:24
Pure.h use-case
#include <functional>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iterator>
using namespace std;