2011/12/13 Ion Gaztañaga
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