看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《yoco (眠月)》之銘言: : 被嗆我難過,回家反省,確定這個直接 template-meta 的版本沒人給過 : #include <cstdio> : template <int N, int M> struct p { C++17 新功能 static-if 根據 compile time constant 展開 不勞煩大家讀難懂的 meta-template programming 版本了 #include <cstdio> template <int n> int f(){ if constexpr(n < 82) { printf("%2d x %2d = %2d\n",(n-1)/9+1,(n-1)%9+1,((n-1)/9+1)*((n-1)%9+1)); f<n + 1>(); } } int main() { f<1>(); } -- To iterate is human, to recurse, divine. L. Peter Deutsch 嫩嫩迴圈 大大遞迴 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.229.131.178 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1533227151.A.8FD.html