2016-11-27 47 views
1

我想在C++中找到std :: set中最大的元素,严格小于给定的元素。有些问题建议寻找LOWER_BOUND迭代器和递减它即C++ set lower_bound()iterator

set<int> st; 
// Add elements 
int x; 
// calculate x 
auto it = st.lower_bound(x); 
if(it != st.begin()) { 
    it--; 
} 

Documentation是不清楚什么类型的迭代器并返回LOWER_BOUND(如远期,双向),所以我们怎么知道这递减迭代器是有效的?我们也可以估算递减std :: set迭代器的复杂度吗?

回答