作者poyenc (髮箍)
看板C_and_CPP
標題Re: [問題] 九九乘法表不用迴圈是叫我直接從1列到81?
時間Fri Nov 30 04:19:28 2018
不會 TMP 所以用 lambda 寫了一個版本:
https://wandbox.org/permlink/icCqZb52J6Q2Zcf1
概念是展開 parameter pack, 形成固定個數的函式呼叫, 用巢狀
結構就可以兜出九九乘法表
[]<
size_t... Ints>(index_sequence<Ints...>,
auto func) {
(
(func)(Ints),
...);
}(
make_index_sequence<
9>{},
[](
auto v) { cout << v << " "; }
);
輸出:
0 1 2 3 4 5 6 7 8
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.76.85
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_and_CPP/M.1543522771.A.59E.html
※ 編輯: poyenc (123.193.76.85), 11/30/2018 19:22:55