Boost logo

Boost Users :

Subject: Re: [Boost-users] [Container] deque emplace() requirements
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2011-12-13 15:51:49


2011/12/13 Ion Gaztañaga <igaztanaga_at_[hidden]>:
> El 13/12/2011 13:23, Szymon Gatner escribió:
>
>> Hi,
>>
>> question: why container::deque<T>::emplace_back() requires T to be
>> copyable?
>>
>> Shouldn't it just be using placement new operator with passed c-tor
>> params?
>>
>> Unless growing of deque causes elements to be copied which is not what I
>> want at all (hence deque and not vector).
>
>
> You are right, it's a bug. I'll try to fix it when I get some time.
>

Thanks! Maybe I can help tho?

I am actually trying to use deque<T> as a simple and efficient replacement for
heap allocated objects. Something along the lines:

class Foo : noncopyable {}

container::deque<Foo> foos;

template <class Iter>
void freeFoo(Iter it, Foo* ptr); // will mark slot as free

shared_ptr<Foo> makeFoo()
{
  // magic here: dynamically allocated object
  foos.emplace_back();
  return make_shared<Foo>(&foos.back(), bind(freeFoo, --foos.end()));
}

I guess using allocate_shared() with custom allocator that would be
emplacing in deque would provide similar functionality.

Cheers,
Simon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net