An intrusive list with const‐time size() method.
Synopsis
Declared in <folly/container/IntrusiveList.h>
template<
typename T,
SafeIntrusiveListHookT::* PtrToMember>
using CountedIntrusiveList = boost::intrusive::list<T, boost::intrusive::member_hook<T, SafeIntrusiveListHook, PtrToMember>, boost::intrusive::constant_time_size<true>>;
Description
A CountedIntrusiveList always uses a safe‐link hook. CountedIntrusiveList::size() is an O(1) operation. Users of this type of lists need to remove a member from a list by calling one of the methods on the list (e.g., erase(), pop_front(), etc.), rather than calling unlink on the member's list hook. Given references to a list and a member, a constant‐time removal operation can be accomplished by list.erase(list.iterator_to(member)). Also, when a member is destroyed, it is NOT automatically removed from the list.
Example usage:
class Foo { // Note that the listHook member variable needs to be visible // to the code that defines the CountedIntrusiveList instantiation. // The list hook can be made public, or you can make the other class a // friend. SafeIntrusiveListHook listHook; };
using FooList = CountedIntrusiveList<Foo, &Foo::listHook> FooList;
Foo *foo = new Foo(); FooList myList; myList.push_back(*foo); myList.pop_front();
Note that each SafeIntrusiveListHook can only be part of a single list at any given time. If you need the same object to be stored in two lists at once, you need to use two different SafeIntrusiveListHook member variables.
The elements stored in the list must contain an SafeIntrusiveListHook member variable.
Created with MrDocs