Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2022-04-03 23:55:13


On 4/4/22 01:58, Marshall Clow via Boost wrote:
> On Apr 3, 2022, at 3:09 PM, Viktor Sehr <viktor.sehr_at_[hidden] <mailto:viktor.sehr_at_[hidden]>> wrote:
>>
>> Why not return a pointer/nullptr instead? pfind_if
>
> Why not just check to see if the returned iterator == end () ?

Exactly. The iterator has the added benefit that it can be used with the
container to perform further operations (e.g. remove the element).

The only benefit of pointer/optional is that is allows to decouple the
element from the container (e.g. if you want to hide the container type
from the caller), and this can be achieved with a trivial wrapper function.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk