0

I am doing a search in a std::list and I am using find from the algorithm header, I saw the reference and it says that it returns last if it doesn't find any value that is equal to mine.

I wonder if I should test after this if the last value is actually equal to my value.

Am I thinking correctly or is there a more elegant solution?

joaomlap
  • 195
  • 3
  • 13
  • 2
    it returns end (not last), and end is one past the last element so you only have to check if the return is end to see if it found the value or not. That being said *don't use list* – Borgleader Jul 29 '15 at 23:39
  • 1
    Thanks, that's what I was wondering about. So if it is == to list.end() I know that there is not a match? Great! Why shouldn't I use them? – joaomlap Jul 29 '15 at 23:41
  • 1
    @joaomlap in most cases you are better off using a `std::vector` it is faster. – Chris Drew Jul 29 '15 at 23:53
  • 1
    @WorldSEnder I wasn't starting a new topic, I was responding to the question above about why not to use `std::list`. – Chris Drew Jul 30 '15 at 00:12

0 Answers0