Re: [分享] typedef dereference of a type
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
推
12/31 13:15, , 1F
12/31 13:15, 1F
推
12/31 14:11, , 2F
12/31 14:11, 2F
推
01/01 11:03, , 3F
01/01 11:03, 3F
推
01/01 13:40, , 4F
01/01 13:40, 4F
→
01/01 13:41, , 5F
01/01 13:41, 5F
推
01/01 20:10, , 6F
01/01 20:10, 6F
→
01/01 21:55, , 7F
01/01 21:55, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 5 篇):