看板 Programming 關於我們 聯絡資訊
※ 引述《mikemagic88 (Mikemagic88)》之銘言: : 使用者輸入1 印1-9 : 使用者輸入2 印1-98 (11, 22, 33等重複的不印) : 使用者輸入3 印1-987 (121, 988, 667等有重複的不印) 用 compile 的 error message 來印: (好讀版 https://gist.github.com/LCamel/9f5305d53d11dfe96d73ebda7c23048e ) template <int i> struct Print { enum : int { v = (void) i // die! };}; template <int i, bool b> struct Test { enum : int { v = 42 };}; template <int i > struct Test<i, false> { enum : int { v = 42 };}; template <int i > struct Test<i, true> { enum : int { v = Print<i>::v };}; template <int i, int d2, int d1, int d0> struct Digits { enum : int { v = Test<i, d2 == 0 ? (d1 == 0 || d1 != d0) : d2 != d1 && d1 != d0 && d0 != d2 >::v };}; template <int i> struct Loop { enum : int { p = Digits<i, i / 100, (i / 10) % 10, i % 10>::v, v = Loop<i + 1>::v };}; template <> struct Loop<1000> { enum : int { v = 42 };}; Loop<1> go; 列印方法: g++ -std=c++0x -ftemplate-depth=1001 a.cpp 2>&1 | grep -oP '(?<=Print<)\d+' (應該可以再短 不過先湊到能跑...) LCamel -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.229.105.20 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1481568735.A.6D7.html
CindyLinz: 笑惹.... XD 112.121.78.5 12/13 03:23
mars90226: 強,template meta programming118.163.127.250 12/13 13:13
※ 編輯: LCamel (114.45.180.161), 12/14/2016 08:38:47
ptt0211: XDDDDDD太會了吧140.114.207.107 12/15 03:26
suhorng: 本串最佳 XDDD 220.137.5.133 12/15 10:22
Frozenmouse: 讚wwww 59.115.170.60 12/15 23:43
LCamel: 呃 後來發現位數寫死了 還請多包涵 111.248.43.99 12/18 17:36