distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
SwapPopQueueFunctor.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_SWAPPOPQUEUEFUNCTOR_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_SWAPPOPQUEUEFUNCTOR_HPP_
14 
16 
17 #include <utility>
18 
19 namespace distortos
20 {
21 
22 namespace internal
23 {
24 
31 template<typename T>
33 {
34 public:
35 
43  constexpr explicit SwapPopQueueFunctor(T& value) :
44  value_{value}
45  {
46 
47  }
48 
56  void operator()(void* const storage) const override
57  {
58  auto& swappedValue = *reinterpret_cast<T*>(storage);
59  using std::swap;
60  swap(value_, swappedValue);
61  swappedValue.~T();
62  }
63 
64 private:
65 
67  T& value_;
68 };
69 
70 } // namespace internal
71 
72 } // namespace distortos
73 
74 #endif // INCLUDE_DISTORTOS_INTERNAL_SYNCHRONIZATION_SWAPPOPQUEUEFUNCTOR_HPP_
T & value_
reference to object that will be used to return popped value
Definition: SwapPopQueueFunctor.hpp:67
Definition: SwapPopQueueFunctor.hpp:32
Top-level namespace of distortos project.
QueueFunctor class header.
void swap(IntrusiveForwardListNode &left, IntrusiveForwardListNode &right)
Swaps contents of two nodes.
Definition: IntrusiveForwardList.hpp:172
void operator()(void *const storage) const override
Swaps the element in the queue&#39;s storage with the value provided by user and destroys this value when...
Definition: SwapPopQueueFunctor.hpp:56
QueueFunctor is a type-erased interface for functors which execute some action on queue&#39;s storage (li...
Definition: QueueFunctor.hpp:31
constexpr SwapPopQueueFunctor(T &value)
SwapPopQueueFunctor&#39;s constructor.
Definition: SwapPopQueueFunctor.hpp:43