Skip to content

Instantly share code, notes, and snippets.

// せつめい
// C++ 0x で関数と引数を pack したタプルから関数適用を行う apply を実装した。
// apply を実装するには tuple の値を variadic arguments に変換する必要がある。
// 束縛済み引数の数で特殊化してやる。0 なら関数を呼ぶ。 1 以上の場合は値を一つずつ積んでいく。
// 返値型を求めようと auto impl(...) -> decltype(impl(...)) のようなコードを書くのは正しくない。
// impl の宣言に impl を利用することは当然できない。それが実際には異なるパラメータを持つ関数テンプレートであったとしても…
// declval を使って fun の返値を求めることで解決する。
#include <tuple>
#include <type_traits>
// 今手元に 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;