util/IntrusiveList: add size()

This commit is contained in:
Max Kellermann 2022-06-09 09:47:56 +02:00 committed by Max Kellermann
parent 1fb858e2d7
commit e437cc4faf

View File

@ -207,6 +207,8 @@ class IntrusiveList {
} }
public: public:
using size_type = std::size_t;
constexpr IntrusiveList() noexcept = default; constexpr IntrusiveList() noexcept = default;
IntrusiveList(IntrusiveList &&src) noexcept { IntrusiveList(IntrusiveList &&src) noexcept {
@ -255,6 +257,10 @@ public:
return head.next == &head; return head.next == &head;
} }
constexpr size_type size() const noexcept {
return std::distance(begin(), end());
}
void clear() noexcept { void clear() noexcept {
if constexpr (std::is_base_of<SafeLinkIntrusiveListHook, T>::value) { if constexpr (std::is_base_of<SafeLinkIntrusiveListHook, T>::value) {
/* for SafeLinkIntrusiveListHook, we need to /* for SafeLinkIntrusiveListHook, we need to