I want to find the greatest element in a std::set in C++ strictly less than a given element. Some questions suggest finding lower_bound iterator and decrementing it i.e.
set<int> st;
// Add elements
int x;
// calculate x
auto it = st.lower_bound(x);
if(it != st.begin()) {
it--;
}
Documentation is unclear as to what type of iterator does lower_bound return (e.g Forward, Bidirectional) so how do we know decrementing this iterator is valid ? Also can we estimate the complexity of decrementing std::set iterator ?