On Apr 3, 2022, at 5:01 PM, Gavin Lambert via Boost
On 4/04/2022 10:58, Marshall Clow wrote:
On Apr 3, 2022, at 3:09 PM, Viktor Sehr wrote:
Why not return a pointer/nullptr instead? pfind_if
Why not just check to see if the returned iterator == end () ?
The annoyance with the iterator == end() implementation is that it's a double indirection -- if you want to access the value afterwards it has to be in a separate statement, which means you can't do it with an rvalue collection.
The same applies with a pointer-find; it's still a non-owning indirection that's invalid on rvalue collections.
The optional return doesn't have that problem; because it copies the value, the value remains valid when returned from an rvalue collection.
Actually, that’s not what Ivan proposed.
He proposed returning an optional