1樓:遊客賬戶0x0
C++模版就是乙個programmable inliner,乙個標準化的code gen方法。
對比:Lisp/Julia/Nim:hygienicMeta OCaml: typed
python:reflection
上面全部:更漂亮的syntax
2樓:Anqur
唔好像有 RankNTypes 耶。
template
typenameFn= int(T) >struct foo; template typename Fn>using foo_t =typename foo Fn>:: type ;using rank3_t =int (int (foo_t ));唔 dependent types 貌似也能搞一搞,比如 std::integral_constant<> 的存在。 想要強行爆破編譯器的 type checking 理論上應該可行,不過給它手寫個 termination checking 恐怕巨醜無比(猜測應該寫的出來)。但想要爆破 type inference?剛第乙個例子都不能寫到一行去咋爆破……(來試試單行寫 ((forall a . a -> int) -> int) -> int)。然後操作字串還得是 GNU extension,還得 template …… 還沒 concept 時這個 typename T 就是個 duck-typed 的仔。衛生巨集和 HOAS 應該是活在夢裡的東西。 然後這麼一想其實挺強的?!限定版 parametric polymorphism + dependent types 是也! (聚聚們輕噴…) 3樓:暮無井見鈴 (俺不懂其他語言) 模板本質上更多是乙個型別運算器,雖然也能兼具型別生成器。 說它強,是和其他 C++ 編譯時的設施比。因為 CXX 裡沒它就無法做絕大多數型別運算了。 然而模板做型別運算還是比較彆扭的。此問題 C++98 裡特別嚴重, C++11~20 都在不斷改進。 王賽 左值和右值,指的不是變數本身的型別,而是變數構成的表示式值型別。表示式值型別是左值還是右值,有一套完整的定義規則,cppreference 上有,手機上答題,不方便找。針對這個題目,三個變數做引數,都屬於 id expression,屬於 lvaue 表示式,對應的具體型別實際上是 int 那... 首先,偏特化正確的寫法是。template template typename Alloc class ContainerT struct Traits 但是 clang 和 msvc 認為這不能構成偏特化。所以我們加個預設的 typename 可以編譯成功。template template CT... Matthew 贊同d41d8c的答案,並且試驗了一下,using是只是別名,無法用它來做deduce,自己寫個型別就可以了 include include template using string view test std basic string view template struct s...C 模板型別推斷和引用摺疊的聯絡?
C 如何對模板中的模板進行偏特化?
這個C 模板為何通不過?