Compare commits
2 Commits
c328859e2d
...
c6e1c93b67
| Author | SHA1 | Date |
|---|---|---|
|
|
c6e1c93b67 | |
|
|
5145c5894c |
|
|
@ -6,6 +6,7 @@
|
||||||
#define UDIFF_CONST_LIST_H_
|
#define UDIFF_CONST_LIST_H_
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
|
@ -104,11 +105,8 @@ namespace cc {
|
||||||
constexpr const_list& operator=(const const_list&) = delete;
|
constexpr const_list& operator=(const const_list&) = delete;
|
||||||
constexpr const_list& operator=(const_list&& other) noexcept;
|
constexpr const_list& operator=(const_list&& other) noexcept;
|
||||||
constexpr const_list& operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
|
constexpr const_list& operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
|
||||||
|
|
||||||
constexpr void assign(size_type count, const value_type& value) noexcept;
|
constexpr void assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept;
|
||||||
template<std::input_iterator InputIt>
|
|
||||||
constexpr void assign(InputIt first, InputIt last);
|
|
||||||
constexpr void assign(std::initializer_list<value_type> values);
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference front() noexcept{ return *_start; }
|
[[nodiscard]] constexpr reference front() noexcept{ return *_start; }
|
||||||
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
|
[[nodiscard]] constexpr const_reference front() const noexcept { return *_start; }
|
||||||
|
|
@ -212,11 +210,19 @@ namespace cc {
|
||||||
const_list_node *_prev = nullptr;
|
const_list_node *_prev = nullptr;
|
||||||
const_list_node *_next = nullptr;
|
const_list_node *_next = nullptr;
|
||||||
const_list<D> *_owner = nullptr;
|
const_list<D> *_owner = nullptr;
|
||||||
|
|
||||||
|
void (*_delete_cb)() = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr const_list_node() noexcept { asserts(); }
|
constexpr const_list_node() noexcept { asserts(); }
|
||||||
virtual constexpr ~const_list_node();
|
virtual constexpr ~const_list_node();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
constexpr void on_delete(void (*cb)());
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _remove();
|
||||||
|
|
||||||
friend class const_list<D>;
|
friend class const_list<D>;
|
||||||
friend class _const_list_iterator_base<D>;
|
friend class _const_list_iterator_base<D>;
|
||||||
};
|
};
|
||||||
|
|
@ -312,17 +318,59 @@ namespace cc {
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
constexpr const_list<Node> &const_list<Node>::operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
|
constexpr const_list<Node> &const_list<Node>::operator=(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
|
||||||
{
|
{
|
||||||
*this = const_list(init);
|
assign(init);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Node>
|
||||||
|
constexpr void const_list<Node>::assign(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept
|
||||||
|
{
|
||||||
|
auto prev = init.begin();
|
||||||
|
prev->get()._owner = this;
|
||||||
|
|
||||||
|
for (auto it = std::next(init.begin()); it != init.end(); ++it) {
|
||||||
|
prev->get()._next = std::addressof(it->get());
|
||||||
|
it->get()._prev = std::addressof(prev->get());
|
||||||
|
it->get()._owner = this;
|
||||||
|
|
||||||
|
prev = it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Node>
|
||||||
|
void const_list<Node>::clear() noexcept
|
||||||
|
{
|
||||||
|
for (auto node : *this) {
|
||||||
|
node._remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename D>
|
template<typename D>
|
||||||
constexpr const_list_node<D>::~const_list_node()
|
constexpr const_list_node<D>::~const_list_node()
|
||||||
{
|
{
|
||||||
|
if (_delete_cb)
|
||||||
|
(*_delete_cb)();
|
||||||
_owner->remove(*this);
|
_owner->remove(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename D>
|
||||||
|
constexpr void const_list_node<D>::on_delete(void (*cb)())
|
||||||
|
{
|
||||||
|
_delete_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename D>
|
||||||
|
void const_list_node<D>::_remove()
|
||||||
|
{
|
||||||
|
if (_delete_cb)
|
||||||
|
(*_delete_cb)();
|
||||||
|
|
||||||
|
_prev = nullptr;
|
||||||
|
_next = nullptr;
|
||||||
|
_owner = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // cc
|
} // cc
|
||||||
|
|
||||||
#endif //UDIFF_CONST_LIST_H_
|
#endif //UDIFF_CONST_LIST_H_
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue