[Container] deque emplace() requirements
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). Cheers, Simon -- Szymon Gatner The Lordz Games Studio www.thelordzgamesstudio.com
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. Ion
2011/12/13 Ion Gaztañaga <igaztanaga@gmail.com>:
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
El 04/01/2012 12:50, Szymon Gatner escribió:
2011/12/13 Ion Gaztañaga<igaztanaga@gmail.com>:
You are right, it's a bug. I'll try to fix it when I get some time.
Got a chance to take a look at this?
I think it's fixed in trunk, you'll need to update Boost.Intrusive as well. Best, Ion
participants (3)
-
Ion Gaztañaga
-
Szymon Gatner
-
Thorsten Ottosen