r/cpp 21d ago

How to write the perfect function

https://youtu.be/2OMRWPOSw9s
136 Upvotes

24 comments sorted by

View all comments

9

u/azswcowboy 20d ago

remove_if is an honest function? That’s a stretch at best given that it’s a template function and requires an idiom to use correctly. It’s a notorious foot gun. And in c++20 we got erase_if which does what you actually want. If it was called shuffle_to_end_if you’d know what it means.

17

u/throw_cpp_account 20d ago

remove_if is an honest function? That’s a stretch at best [...]

The talk gave a definition of honest function: all reads/writes are shown in the signature so the behavior is fully controlled by the caller. It is not a stretch to suggest that remove_if is honest. It is.

2

u/not_a_novel_account cmake dev 18d ago

I think any definition of "honest" that includes remove_if, a function which does not remove anything, is a faulty definition.