Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possibly wrong behavior with std::remove_if #192

Merged
merged 2 commits into from
Jun 24, 2024

Conversation

jmcarcell
Copy link
Contributor

Using std::remove_if alone only does some rearranging and changing elements of _blocks, and that doesn't seem what's intended there. If everyone is using C++20 std::erase_if can be used instead of the erase - remove idiom.

BEGINRELEASENOTES

  • Fix possibly wrong behavior with std::remove_if with a erase - remove idiom

ENDRELEASENOTES

@@ -29,7 +28,7 @@ namespace IOIMPL {
//----------------------------------------------------------------------------

void LCEventLazyImpl::removeCollection(const std::string & name) {
std::remove_if( _blocks.begin(), _blocks.end(), [&]( const sio::block_ptr &blk ){ return (blk->name() == name) ; } ) ;
_blocks.erase( std::remove_if( _blocks.begin(), _blocks.end(), [&]( const sio::block_ptr &blk ){ return (blk->name() == name) ; } ), _blocks.end() ) ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you by chance know if block_ptr is a smart pointer, or in any other way managed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shared_ptr. Deletions were already happening in the remove_if because _blocks will have a first to be discarded with some elements and a second one with the elements that remain, but the first part + the second part isn't the same as the original vector, some may be repeated which means others have to be missing. Hard to explain, easier to test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. If it's managed than it's OK. I was just wondering whether we had to manually delete them before eraase

@tmadlener tmadlener merged commit 473755a into iLCSoft:master Jun 24, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants