Namespaces
Variants
Views
Actions

Talk:cpp/algorithm/find

From cppreference.com

[edit] Return value

Iterator to the first element satisfying the condition or last if no such element is found... Why "last"? Doesn't it return "-1"? Rosstopher (talk) 06:32, 10 June 2015 (PDT)

no, it doesn't return -1. Perhaps you're thinking of std::string::find? --Cubbi (talk) 06:43, 10 June 2015 (PDT)


I find this still very irritating. It does not return the "last" element or an iterator to the "last" element. It returns an iterator to "end" if the specified element was not found. I would suggest to change the term.

I do agree that "last" is an objectively terrible name and would like to see it changed to "end", I guess the only concern there is that begin and end are identifiers in the std namespace. --Ybab321 (talk) 07:18, 27 May 2021 (PDT)
what would be a better replacement for [first, last) pairs through the algorithm pages? [beg, end) could work, I think the only mild ambiguity is with the end() member functions (not so much with the free std::end). They could also be named to be obviously iterators e.g. [beg_it, end_it). Anything else? --Cubbi (talk) 14:22, 27 May 2021 (PDT)
[beg_it, end_it) is fine by me, I actually use [it_begin, it_end) in my personal code, any variation on this works for me. Open to other suggestions of course. --Ybab321 (talk) 16:16, 27 May 2021 (PDT)