Boost logo

Boost :

From: Ivan Matek (libbooze_at_[hidden])
Date: 2022-03-22 21:09:28


Hi,
I have been thinking for this for a long time so I wanted to get the
feedback from others.

As you probably know better than me there is a bit of a drama
<https://brevzin.github.io/c++/2021/12/13/optional-ref-ptr/>when it comes
to std::optional<T&> and from what I see it will not be in C++23 for sure.
I believe this gives an opportunity to boost to provide something nice for
the users.

Now the issues are the following:
AFAIK boost only has old ranges and iterator based algorithms, ideally we
would just have something like std:: ranges and add the ofind/ofind_if to
those, but AFAIK those do not exist.
So I think best thing would be to add it to boost::algorithm
<https://github.com/boostorg/algorithm/tree/develop/include/boost/algorithm>
.
There are further questions like, should boost containers like
map/unordered_map gain similar functionality, but I think deciding if we
want the general algorithm is the first step.

Another option I can think of is that those algorithms return something
like a 0 or 1 element view(so you could access the optional value with
range based for loop). This seems weird to me, so I would prefer
boost::optional<T&>.

There is s a short example on godbolt <https://godbolt.org/z/W9K3na9Gc>,
but don't look at implementation too much, it was just something I hacked
quickly, I am mostly interested in in feedback on if functionality would be
nice addition to boost.

regards,
Ivan


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