Set parent when adding automatically
This commit is contained in:
parent
c25103e680
commit
2812c7bd0a
5 changed files with 30 additions and 30 deletions
|
|
@ -21,6 +21,11 @@ namespace cppast
|
|||
{
|
||||
std::unique_ptr<T> next_;
|
||||
|
||||
void do_on_insert(const T& parent) noexcept
|
||||
{
|
||||
static_cast<T&>(*this).on_insert(parent);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
friend struct intrusive_list_access;
|
||||
};
|
||||
|
|
@ -42,6 +47,12 @@ namespace cppast
|
|||
obj.next_ = std::move(node);
|
||||
return obj.next_.get();
|
||||
}
|
||||
|
||||
template <typename U, typename V>
|
||||
static void on_insert(U& obj, const V& parent)
|
||||
{
|
||||
obj.do_on_insert(parent);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -111,7 +122,8 @@ namespace cppast
|
|||
intrusive_list() = default;
|
||||
|
||||
//=== modifiers ===//
|
||||
void push_back(std::unique_ptr<T> obj) noexcept
|
||||
template <typename U>
|
||||
void push_back(const U& parent, std::unique_ptr<T> obj) noexcept
|
||||
{
|
||||
DEBUG_ASSERT(obj != nullptr, detail::assert_handler{});
|
||||
|
||||
|
|
@ -125,6 +137,8 @@ namespace cppast
|
|||
first_ = std::move(obj);
|
||||
last_ = type_safe::opt_ref(first_.get());
|
||||
}
|
||||
|
||||
intrusive_list_access<T>::on_insert(last_.value(), parent);
|
||||
}
|
||||
|
||||
//=== accesors ===//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue