看板 C_and_CPP 關於我們 聯絡資訊
http://www.cplusplus.com/reference/std/iterator/iterator_traits/ 所以這樣寫就可以了 template < typename IterType > class Foo { typedef typename std::iterator_traits<IterType>::value_type ValueType; } ; iterator_traits 的優點是不需要 c++0x 的 decltype 而且它會幫你去掉 const 與 reference 直接用 pointer 當 IterType 也是 OK 的 不過使用者傳入的 IterType 必需依照 STL 的慣例進行定義 也就是 IterType 自己要有 value_type/reference_type 等等的 member type 如果你預設 user 只會傳 pointer 和 STL iterator 那 iterator_traits 是最方便的解法 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.15.163
yoco315:可惡 果然有這種東西 XD 我就想說沒有的話很奇怪 12/31 13:15
loveme00835:XD 12/31 14:11
VictorTom:推XD 01/01 11:03
avhacker:其實可以用 Boost.TypeTraits,裡面的東西多到嚇人 01/01 13:40
avhacker:http://goo.gl/r5AJX 01/01 13:41
tomap41017:第一時間就想到iter_traits不過想到用法就..>< 01/01 20:10
loveme00835:是阿...不適用的要想辦法覆寫掉 01/01 21:55