1月 5 2016 Template-template parameters 虽说早就听闻C++的模版是图灵完全的,不过当看到这样的用法的时候,还是不禁感叹这实在是太酷了!写Haskell风格的C++指日可待! 123456789101112131415161718192021222324252627282930313233template <template <typename> class m>struct Monad { template <typename a> static m<a> mreturn(const a&); template <typename a, typename b> static m<b> mbind(const m<a>&, m<b>(*)(const a&));};template <typename a>struct Maybe { bool isNothing; a value;};template <>struct Monad<Maybe> { template <typename a> static Maybe<a> mreturn(const a& v) { Maybe<a> x; x.isNothing = false; x.value = v; return x; } template <typename a, typename b> static Maybe<b> mbind(const Maybe<a>& action, Maybe<b>(*function)(const a&)) { if (action.isNothing) return action; else return function(action.value); }}; 相关链接: Higher-kinded Types with C++ What are some uses of template template parameters in C++? Newer 请问您今天要来点Monad Transformer吗? Older 2015什么的,就这么过完了呢