【发布时间】:2016-11-27 06:26:54
【问题描述】:
我想在 C++ 中的 std::set 中找到严格小于给定元素的最大元素。一些问题建议找到 lower_bound 迭代器并将其递减,即
set<int> st;
// Add elements
int x;
// calculate x
auto it = st.lower_bound(x);
if(it != st.begin()) {
it--;
}
Documentation 不清楚 lower_bound 返回什么类型的迭代器(例如 Forward、Bidirectional),那么我们怎么知道递减这个迭代器是有效的呢?我们也可以估计递减 std::set 迭代器的复杂度吗?
【问题讨论】:
标签: c++