filfirst says
11 years ago
用recursive的方式來使用c++11的variadic template,有functional programming的味道
latest #13
filfirst says
11 years ago
c++11:
template <typename T>
T Sum(T num) {
return num;
}
filfirst says
11 years ago
template <typename T, typename... Args>
T Sum(T num, Args... args) {
return Sum(args...) + num;
}
filfirst says
11 years ago
auto sum2 = Sum(1, 3, 5, 10, 2);
立即下載
filfirst says
11 years ago
erlang:
filfirst says
11 years ago
sum([]) -> 0;
sum([Num|Rest]) -> sum(Rest) + Num.
filfirst says
11 years ago
Sum2 = sum:sum([1, 3, 5, 10, 2]).
filfirst says
11 years ago
很像吧.(plurk到底要怎麼打程式碼)
filfirst says
11 years ago
bookmark起來了XD
filfirst says
11 years ago
這個從前想做說...好像有跟你討論過
back to top