rippled
|
Intrusive doubly linked list. More...
Public Types | |
using | Node = typename detail::ListNode< T, Tag > |
using | value_type = T |
using | pointer = value_type * |
using | reference = value_type & |
using | const_pointer = value_type const * |
using | const_reference = value_type const & |
using | size_type = std::size_t |
using | difference_type = std::ptrdiff_t |
using | iterator = detail::ListIterator< Node > |
using | const_iterator = detail::ListIterator< Node const > |
Public Member Functions | |
List () | |
Create an empty list. More... | |
List (List const &)=delete | |
List & | operator= (List const &)=delete |
bool | empty () const noexcept |
Determine if the list is empty. More... | |
size_type | size () const noexcept |
Returns the number of elements in the list. More... | |
reference | front () noexcept |
Obtain a reference to the first element. More... | |
const_reference | front () const noexcept |
Obtain a const reference to the first element. More... | |
reference | back () noexcept |
Obtain a reference to the last element. More... | |
const_reference | back () const noexcept |
Obtain a const reference to the last element. More... | |
iterator | begin () noexcept |
Obtain an iterator to the beginning of the list. More... | |
const_iterator | begin () const noexcept |
Obtain a const iterator to the beginning of the list. More... | |
const_iterator | cbegin () const noexcept |
Obtain a const iterator to the beginning of the list. More... | |
iterator | end () noexcept |
Obtain a iterator to the end of the list. More... | |
const_iterator | end () const noexcept |
Obtain a const iterator to the end of the list. More... | |
const_iterator | cend () const noexcept |
Obtain a const iterator to the end of the list. More... | |
void | clear () noexcept |
Clear the list. More... | |
iterator | insert (iterator pos, T &element) noexcept |
Insert an element. More... | |
void | insert (iterator pos, List &other) noexcept |
Insert another list into this one. More... | |
iterator | erase (iterator pos) noexcept |
Remove an element. More... | |
iterator | push_front (T &element) noexcept |
Insert an element at the beginning of the list. More... | |
T & | pop_front () noexcept |
Remove the element at the beginning of the list. More... | |
iterator | push_back (T &element) noexcept |
Append an element at the end of the list. More... | |
T & | pop_back () noexcept |
Remove the element at the end of the list. More... | |
void | swap (List &other) noexcept |
Swap contents with another list. More... | |
iterator | prepend (List &list) noexcept |
Insert another list at the beginning of this list. More... | |
iterator | append (List &list) noexcept |
Append another list at the end of this list. More... | |
iterator | iterator_to (T &element) const noexcept |
Obtain an iterator from an element. More... | |
const_iterator | const_iterator_to (T const &element) const noexcept |
Obtain a const iterator from an element. More... | |
Private Member Functions | |
reference | element_from (Node *node) noexcept |
const_reference | element_from (Node const *node) const noexcept |
Private Attributes | |
size_type | m_size |
Node | m_head |
Node | m_tail |
Intrusive doubly linked list.
This intrusive List is a container similar in operation to std::list in the Standard Template Library (STL). Like all intrusive containers, List requires you to first derive your class from List<>::Node:
Now we define the list, and add a couple of items.
For compatibility with the standard containers, push_back() expects a reference to the object. Unlike the standard container, however, push_back() places the actual object in the list and not a copy-constructed duplicate.
Iterating over the list follows the same idiom as the STL:
You can even use BOOST_FOREACH, or range based for loops:
Because List is mostly STL compliant, it can be passed into STL algorithms: e.g. std::for_each()
or std::find_first_of()
.
In general, objects placed into a List should be dynamically allocated although this cannot be enforced at compile time. Since the caller provides the storage for the object, the caller is also responsible for deleting the object. An object still exists after being removed from a List, until the caller deletes it. This means an element can be moved from one List to another with practically no overhead.
Unlike the standard containers, an object may only exist in one list at a time, unless special preparations are made. The Tag template parameter is used to distinguish between different list types for the same object, allowing the object to exist in more than one list simultaneously.
For example, consider an actor system where a global list of actors is maintained, so that they can each be periodically receive processing time. We wish to also maintain a list of the subset of actors that require a domain-dependent update. To achieve this, we declare two tags, the associated list types, and the list element thusly:
T | The base type of element which the list will store pointers to. |
Tag | An optional unique type name used to distinguish lists and nodes, when the object can exist in multiple lists simultaneously. |
using beast::List< T, Tag >::Node = typename detail::ListNode<T, Tag> |
using beast::List< T, Tag >::value_type = T |
using beast::List< T, Tag >::pointer = value_type* |
using beast::List< T, Tag >::reference = value_type& |
using beast::List< T, Tag >::const_pointer = value_type const* |
using beast::List< T, Tag >::const_reference = value_type const& |
using beast::List< T, Tag >::size_type = std::size_t |
using beast::List< T, Tag >::difference_type = std::ptrdiff_t |
using beast::List< T, Tag >::iterator = detail::ListIterator<Node> |
using beast::List< T, Tag >::const_iterator = detail::ListIterator<Node const> |
beast::List< T, Tag >::List | ( | ) |
|
delete |
|
delete |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
privatenoexcept |
|
privatenoexcept |
|
private |
|
private |
|
private |