作者yoco (眠月)
看板C_and_CPP
标题Re: [问题] 九九乘法表不用回圈是叫我直接从1列到81?
时间Fri Aug 3 00:25:47 2018
※ 引述《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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1533227151.A.8FD.html