C++ Logo

std-proposals

Advanced search

Re: Yet another member function for std::map

From: Ivan Matek <libbooze_at_[hidden]>
Date: Sat, 31 Jul 2021 13:06:31 +0200
2, "return bare pointer," is correct. The STL already uses this idiom in
> `std::get_if` and `std::any_cast`, as well as `std::dynamic_cast<T*>`.
>
IMAO STL uses this wrong(more precisely suboptimal).
Pointer is way too powerful for the return type of this kind of operation.
There is absolutely no reason why one should be able to do arithmetic on
returned value, call delete on it...
I understand that this concerns might sound trivial to people reading this,
but there are millions of C++ developers and many of them are not that good
at C++, so it is nice to make things harder to misuse.

Obviously this is personal opinion (similar to using strong types in
general, practice of using most specialized algorithm when multiple will
work fine, TOTW 112 <https://abseil.io/tips/112>), but I would not just
assume STL did it right in the past when discussing new ideas.

@Kyle
In general excellent proposal, maybe consider adding it to some open source
library first.
I have considered this problem long time ago, and thought maybe ofind would
be a nicer short name(o is for optional), but then issue is that there is
no ofind in <algorithm> so maybe value_for is best name...

Received on 2021-07-31 06:06:46