How can I write my own emplace method in my deque?
For example, I have this emplace_front function
template <typename ... Args>
void emplace_front(Args&& ...val) {
???
}
and Node constructor
template <typename ... Args>
Node(Args&&... val) : element(std::forward<Args>(val)...), next(nullptr),prev(nullptr) { }
I can't figure out how to write it correctly
If you have a continuous container, it looks something like:
This is called 'placement new', and does not allocate, only construct
p
should be aT*
If you have a node-based container, it looks something like:
you also need a constructor to your iterator that takes a
Node*