【发布时间】:2016-07-21 18:52:17
【问题描述】:
Why does boost::find_first take a non-const reference to its input? 处的评论建议“调用者使用 const_iterator 模板参数创建非 const iterator_range 以“证明”迭代对象具有足够的生命周期。”
这是什么意思,我该怎么做?
特别是,如何使用此代码实现 const 正确性?
typedef std::map<int, double> tMyMap;
tMyMap::const_iterator subrange_begin = my_map.lower_bound(123);
tMyMap::const_iterator subrange_end = my_map.upper_bound(456);
// I'd like to return a subrange that can't modify my_map
// but this vomits template errors complaining about const_iterators
return boost::iterator_range<tMyMap::const_iterator>(subrange_begin, subrange_end);
【问题讨论】:
-
奇怪,可能是版本问题。我是 gcc 4.8.4 / Boost 1.55
标签: c++ boost iterator constants const-iterator