Skip to content

Conversation

rolandreichweinbmw
Copy link
Contributor

Besides remove() by reference, I provide this remove() by pointer (overload).

Scenario is as follows:

Current remove() by reference uses the comparison operator, comparing actually different instances for equality. In my use case, I have objects in the intrusive_forward_list which don't have a comparison operator defined but I have a pointer to them. This way, I can intentionally remove the actual object from the list pointed to by the pointer.

@jwellbelove jwellbelove merged commit 37539a2 into ETLCPP:master Mar 1, 2025
63 checks passed
@jwellbelove
Copy link
Contributor

jwellbelove commented Mar 1, 2025

Your unit test test_remove_by_pointer does not remove by pointer.

data0.remove(*element); is removing by reference.
What you meant was data0.remove(element);

I've fixed it in the pulled code.

@rolandreichweinbmw
Copy link
Contributor Author

Thanks for finding and the correct fix. I can confirm it works now also without the "*".

@jwellbelove
Copy link
Contributor

I've also copied the change to etl::intrusive_list.

@jwellbelove
Copy link
Contributor

Actually, as I was editing the intrusive lists, I realised that that there was already an node_type* erase(node_type& node) that basically does what your remove(const_pointer element) does.

It's about 8 years since I wrote the intrusive lists!

@jwellbelove
Copy link
Contributor

I will add a node_type* erase(const node_type* node) and maybe change the node_type* erase(node_type& node) to node_type* erase(const node_type& node)

jwellbelove pushed a commit that referenced this pull request Mar 2, 2025
…-pointer' into development

# Conflicts:
#	include/etl/intrusive_forward_list.h
jwellbelove pushed a commit that referenced this pull request Mar 2, 2025
* Add intrusive_forward_list::remove() element by pointer

* Add test
jwellbelove pushed a commit that referenced this pull request Mar 28, 2025
* Add intrusive_forward_list::remove() element by pointer

* Add test
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