Observable Reference
Generic observable objects for C++
|
Thread-safe collection that can store arbitrary items and apply a functor over them.
All methods of the collection can be safely called in parallel, from multiple threads.
ValueType | Type of the elements that will be stored inside the collection. This type must be at least move constructible. |
Public Types | |
using | id = std::size_t |
Identifier for an element that has been inserted. More... | |
Public Member Functions | |
collection () noexcept=default | |
Create an empty collection. More... | |
template<typename ValueType_ > | |
auto | insert (ValueType_ &&element) |
Insert a new element into the collection. More... | |
auto | remove (id const &element_id) noexcept |
Remove a previously inserted element from the collection. More... | |
template<typename UnaryFunctor > | |
void | apply (UnaryFunctor &&fun) const noexcept(noexcept(fun(std::declval< ValueType >()))) |
Apply a unary functor over all elements of the collection. More... | |
auto | empty () const noexcept |
Return true if the collection has no elements. More... | |
~collection () noexcept | |
Destructor. More... | |
collection (collection const &)=delete | |
Collections are not copy-constructible. More... | |
auto | operator= (collection const &) -> collection &=delete |
Collections are not copy-assignable. More... | |
collection (collection &&)=delete | |
Collections are move-constructible. More... | |
auto | operator= (collection &&) -> collection &=delete |
Collections are move-assignable. More... | |
using observable::detail::collection< ValueType >::id = std::size_t |
Identifier for an element that has been inserted.
You can use this id to remove a previously inserted element.
|
defaultnoexcept |
Create an empty collection.
|
inlinenoexcept |
Destructor.
|
delete |
Collections are not copy-constructible.
|
delete |
Collections are move-constructible.
|
inline |
Insert a new element into the collection.
[in] | element | The object to be inserted. |
ValueType_ | Type of the inserted element. Must be convertible to the collection's ValueType. |
|
inlinenoexcept |
Remove a previously inserted element from the collection.
If no element with the provided id exists, this method does nothing.
[in] | element_id | Id of the element to remove. This is returned by insert. |
|
inlinenoexcept |
Apply a unary functor over all elements of the collection.
The functor will be called multiple times, with each element, in an unspecified order.
[in] | fun | A functor that will be called with each element of the collection. The functor must be assignable to a std::function<void(ValueType const &)> . |
UnaryFunctor | Type of the fun parameter. |
|
inlinenoexcept |
Return true if the collection has no elements.
|
delete |
Collections are not copy-assignable.
|
delete |
Collections are move-assignable.