Skip to content

Instantly share code, notes, and snippets.

@splinterofchaos
splinterofchaos / zip-map-tuple.cpp
Created December 12, 2012 14:17
More fun with tuples.
#include <tuple>
#include <iostream>
template< size_t ...i > struct IndexList {};
template< size_t ... > struct EnumBuilder;
// Increment cur until cur == end.
template< size_t end, size_t cur, size_t ...i >
@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 / 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 >
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
// Full disclosure: This is based on another gist, but I neglected to write down the link to it.
[CreateAssetMenu]
public class IconPacker : ScriptableObject {
public Texture2D[] textures;
// compile with g++ ecs.cpp -std=c++2a -o run && ./run
// Taken from my project, https://github.com/splinterofchaos/py-srpg
#include <vector>
#include <tuple>
#include <iostream>
template<typename F, typename...T>
constexpr auto tuple_map(F&& f, const std::tuple<T...>& t) {
return std::tuple(f(std::get<T>(t))...);
#include <memory>
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
struct Seq {
size_t start, size;
};
ostream& operator<<(ostream& os, const Seq& s) {
return os << "[" << s.start << ", " << s.size << ")";
}
// Returns the number of replacements or additions required to break sequences to have no triplets.
@splinterofchaos
splinterofchaos / list.cpp
Created December 15, 2012 01:03
Several of Haskell's Data.List functions implemented in C++ Data.List: http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html
#include <algorithm>
#include <vector>
#include <iterator>
#include <iostream>
template< class F, class X, class S >
constexpr X foldl( F&& f, X x, const S& s ) {
return std::accumulate (
std::begin(s), std::end(s),
diff --git a/include/ftl/function.h b/include/ftl/function.h
index 1911efa..c9ccc54 100644
--- a/include/ftl/function.h
+++ b/include/ftl/function.h
@@ -350,13 +350,30 @@ namespace ftl {
template<typename R, typename P1, typename P2, typename...Ps>
struct curried<R,P1,P2,Ps...> {
-
- function<R(P2,Ps...)> operator() (P1 p1) const {
diff --git a/include/ftl/function.h b/include/ftl/function.h
index 1911efa..605db4f 100644
--- a/include/ftl/function.h
+++ b/include/ftl/function.h
@@ -331,6 +331,7 @@ namespace ftl {
/* TODO: Make currying work even when we give N > 1, N < Nparams
* arguments to a function of Nparams parameters.
*/
+
template<typename...>