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
// せつめい | |
// C++ 0x で関数と引数を pack したタプルから関数適用を行う apply を実装した。 | |
// apply を実装するには tuple の値を variadic arguments に変換する必要がある。 | |
// 束縛済み引数の数で特殊化してやる。0 なら関数を呼ぶ。 1 以上の場合は値を一つずつ積んでいく。 | |
// 返値型を求めようと auto impl(...) -> decltype(impl(...)) のようなコードを書くのは正しくない。 | |
// impl の宣言に impl を利用することは当然できない。それが実際には異なるパラメータを持つ関数テンプレートであったとしても… | |
// declval を使って fun の返値を求めることで解決する。 | |
#include <tuple> | |
#include <type_traits> |
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
// 今手元に 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; |
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
auto f(tag_type t) -> val { | |
switch (t) { | |
case A: return a(); | |
case B: return b(); | |
... | |
default: assert(false); /* return ??? */ | |
} | |
assert(false); | |
/* return ??? */ | |
} |
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 <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; }; |
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
まず | |
AAA | |
BBB | |
みたいなのじゃ困る、という要求があって | |
process { | |
lock m | |
modify v |
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
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; | |
}; |
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 <cstdio> | |
#include <iostream> | |
#include <typeinfo> | |
#include <cxxabi.h> | |
char* demangle(const char *demangle) { | |
int status; | |
return abi::__cxa_demangle(demangle, 0, 0, &status); | |
} |
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 <cstdio> | |
template <typename... seq> | |
struct array; | |
template <typename ary> | |
struct head; | |
template <typename first, typename... rest> | |
struct head<array<first, rest...>> { |
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
--- 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; |
NewerOlder