Compare commits

..

No commits in common. "c6e1c93b67d2ac936293ff4440a8d1a82ba1f699" and "c328859e2d16d0b57c1ce1a638c50499b670d24e" have entirely different histories.

1 changed files with 8 additions and 56 deletions

View File

@ -6,7 +6,6 @@
#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>
@ -106,7 +105,10 @@ namespace cc {
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(std::initializer_list<std::reference_wrapper<value_type>> init) noexcept; constexpr void assign(size_type count, const value_type& value) 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; }
@ -211,18 +213,10 @@ namespace cc {
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>;
}; };
@ -318,59 +312,17 @@ 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
{ {
assign(init); *this = const_list(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_