Commit 1712ca18 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: add emplace function in double flat list

parent 1e77753f
......@@ -1604,6 +1604,8 @@ public:
std::swap(list, other.list);
std::swap(node, other.node);
}
friend class flat_double_list<T>;
};
class const_iterator
......@@ -1694,6 +1696,8 @@ public:
std::swap(list, other.list);
std::swap(node, other.node);
}
friend class flat_double_list<T>;
};
private:
......@@ -1814,6 +1818,33 @@ public:
return m_back->value;
}
/**
* @brief Inserts a new element into the container directly before pos.
* @tparam ...Args
* @param pos
* @param ...args
* @return
*/
template<typename... Args>
iterator emplace(iterator pos, Args&&... args) noexcept
{
if (!pos.node)
return emplace_back(std::forward<Args>(args)...);
if (!pos.node->prev)
return emplace_front(std::forward<Args>(args)...);
node_type* new_node = m_allocator->alloc();
new (&new_node->value) T(std::forward<Args>(args)...);
++m_size;
new_node->prev = pos.node->prev;
new_node->next = pos.node;
pos.node->prev->next = new_node;
pos.node->prev = new_node;
return iterator(this, new_node);
}
template<typename... Args>
iterator emplace_front(Args&&... args) noexcept
{
......
......@@ -597,6 +597,18 @@ main()
--it;
expect(*it == 7);
}
lst.emplace(lst.begin(), 10);
expect(*lst.begin() == 10);
{
auto it = lst.begin();
++it;
it = lst.emplace(it, 11);
expect(*it == 11);
expect(*lst.begin() == 10);
}
};
"data_array_api"_test = [] {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment