Skip to content

Instantly share code, notes, and snippets.

// 今手元に variadic templates をサポートした gcc がない(なんなら gcc 自体ない)からコンパイルが試せていない
// f 0 0 = [0]
// f n 0 = []
// f n m = n : f n m - 1
// g n = f n n
// h n = foldl (++) [] $ map g (0 .. n)
template <int... seq>
struct ilist;
@niha
niha / return.cpp
Created November 21, 2010 07:36
適切な expression が書けないよの例
auto f(tag_type t) -> val {
switch (t) {
case A: return a();
case B: return b();
...
default: assert(false); /* return ??? */
}
assert(false);
/* return ??? */
}
#include <tuple>
#include <functional>
#include <cstdio>
using namespace std;
template <typename T>
struct tuple_head;
template <typename Head, typename... Tail>
struct tuple_head<tuple<Head, Tail...>> { typedef Head type; };
まず
AAA
BBB
みたいなのじゃ困る、という要求があって
process {
lock m
modify v
template <bool cond, typename _, typename else_>
struct enable_if { typedef typename else_::type type; };
template <typename then_, typename _>
struct enable_if<true, then_, _>{ typedef typename then_::type type; };
template <int n>
struct num {
static const int value = n;
typedef num<n> type;
};
#include <cstdio>
#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
char* demangle(const char *demangle) {
int status;
return abi::__cxa_demangle(demangle, 0, 0, &status);
}
#include <cstdio>
template <typename... seq>
struct array;
template <typename ary>
struct head;
template <typename first, typename... rest>
struct head<array<first, rest...>> {
let w:gx_history_list = [{}]
let w:gx_history_current_index = 0
let w:gx_original_qflist = {}
function! s:GetCurrentQFIndex()
let qflist = getqflist()
if empty(qflist)
return -1
endif
--- ls-files.c 2010-07-02 00:29:48.206993409 +0900
+++ ls-files.c.orig 2010-07-02 00:29:41.022986503 +0900
@@ -13,6 +13,7 @@
#include "parse-options.h"
#include "resolve-undo.h"
#include "string-list.h"
+#include "color.h"
static int abbrev;
static int show_deleted;
// せつめい
// C++ 0x で (T1, T2, ... TN) -> R を T1 -> (T2 -> ... TN)..) -> Ret する curry を実装した。
// tuple に引数を溜めていき、最後に apply を利用して関数を呼び出す。
// decltype は再帰関数のシグネチャには使えないので返値型を計算する type function を書いた。
// enable_if で頑張れば書けそうだけれど(apply 可能かどうか)面倒なのでジェネリックには実装していない。
#include <tuple>
#include <type_traits>
#include <functional>