On 2005-12-13,
<> wrote:
> Hi,
>
> Given:
>
> 1) Custom containers that have nothing to do with vector, deque, list,
> map etc,
> 2) a custom version of new and delete defined for these containers,
> customNew and customDelete, say. When an item is to be inserted/removed
> into/from these custom containers, customNew and customDelete is
> called.
> 3) Iterators are available for these custom containers which adhere to
> the requirements of stl.
>
> // these iterators adhere to the stl requirements for randomaccess
> iterators.
> myContainer::iterator begin = intCont.begin();
> myContainer::iterator end = intCont.end();
>
> // now heres the rub.
> std::sort(begin, end);
>
> I want these alorithms to use customNew and customDelete to get
> memory if needed.
>
> I thought I had to use allocators originally but know I'm
> thinking thats not the case. What exactly do I need to do to
> have std::sort (and other algorithms) use customNew and
> customDelete.
The standard algorithms don't need to allocate or release memory.
They just assign and copy elements. You need to pass special
inserter iterators to get the behavior you're thinking of.
For example:
MyContainer<int> unique_list;
std::unique_copy(begin, end, std::back_inserter(unique_list));
That will work for your container as long as it supports
MyContainer:

ush_back.
--
Neil Cerutti