Opened 6 years ago

Last modified 5 years ago

#12763 new Feature Requests

Provide a way to specify a default disposer

Reported by: fdegros@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: intrusive
Version: Boost 1.63.0 Severity: Optimization
Keywords: Cc: fdegros@…

Description

It would be convenient if there was a way to specify a default disposer to be applied to elements stored in an intrusive container. This would make it easier to write containers that take ownership of their inserted elements.

This would impact the container's destructor as well as the methods erase, erase_after, clear, remove, remove_if, pop_front, pop_back, assign, unique and clone_from.

The library should probably provide a no-op disposer, which would be the default one used by intrusive containers. Particular care should be taken in clear and containers' destructors in order to avoid calling the no-op disposer for every element.

For example:

boost::intrusive::list<MyElement, boost::intrusive::disposer<std::default_delete<MyElement>>> elems;
elems.insert(*new MyElement);

// Clearing the collection deletes the elements.
elems.clear();

Change History (3)

comment:1 by fdegros@…, 6 years ago

Ping? Any idea or progress on this topic?

comment:2 by Ion Gaztañaga, 6 years ago

Configuring the deleter would require also a cloner for some functions. Maybe a wrapper class that manages memory could be helpful, but I have no clear idea on what's the best approach.

comment:3 by fdegros@…, 5 years ago

Where would a cloner be required if we had a default deleter?

Note: See TracTickets for help on using tickets.