std::find on an empty container

G

gwowen

// Is the following well defined
#include <vector>
#include <algorith>

int main()
{
std::vector<int> foo(0,0);
bool cont = (std::find(foo.begin(),foo.end(),1) == foo.end());
// Is cont TRUE at this point
}
 
G

gwowen

Yes, it's true and well-defined.

Thanks Christian. It seemed likely to be the case. My problem was in
a different line, but the optimiser confused the debugger. I'd called
std::max_element on an empty container, and then derefenced the result
without checking it was valid. Bad brain day. Score one for the unit
tests...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top