I'm pretty new to C++ and do not understand all the concepts of the STL library, so bear with me.
I wrote the following code snippet (pasted below) to find the lower_bound in a sorted vector.
Although this code works fine in Release mode, it asserts in debug mode (VStudio-8).
I believe this is because less_equal<int>
is not a strictly weak ordering .
From the following thread: stl ordering - strict weak ordering
I do sort of understand that a weak ordering is imposed by the STL, but I'm still not very clear why?
In my case below I need to use less_equal<int>
since I'm trying to find the nearest element to a given value in a sorted vector.
Is the code snippet below even valid? Also, is there a better way to do it? Also any insights/references to what exactly is weak and partial ordering would be helpful.
int main() {
vector<int> dest;
for(int i = 0;i <6;i++) {
dest.push_back(i);
}
vector<int>::iterator i =
std::lower_bound(dest.begin(),dest.end(),4,less_equal< int >());
return 1;
}