从迭代器中获取 const_iterator

2022-01-10 00:00:00 iterator constants metaprogramming c++ stl

是否有将 iterator 映射到其对应的 const_iterator 的元函数 f?

Is there a metafunction f that maps an iterator to its corresponding const_iterator?

f::iterator>::type 应该产生 std::vector::const_iterator.

推荐答案

我不知道有这样的元函数.

I am not aware of such a metafunction.

并非所有迭代器都有对应的 const_iterator.例如.插入迭代器.所以这样的元函数需要决定在这种情况下它会做什么.

Not all iterators have a corresponding const_iterator. E.g. insert_iterator. So such a metafunction would need to decide what it is going to do in such cases.

相关文章