YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
intrusive_stack.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/log.hpp>
5
6#include <utility>
7
8namespace yaclib::detail {
9
10class Stack final {
11 public:
12 Stack& operator=(const Stack&) = delete;
13 Stack& operator=(Stack&&) = delete;
14 Stack(const Stack&) = delete;
15
17 Stack(Stack&& other) noexcept : _head{std::exchange(other._head, nullptr)} {
18 }
19
20 void PushFront(Node& node) noexcept {
21 node.next = _head;
22 _head = &node;
23 }
24
25 // Mostly convinient helper to use lifo order instead of fifo order with List
26 void PushBack(Node& node) noexcept {
27 return PushFront(node);
28 }
29
31 return _head == nullptr;
32 }
33
36 return *std::exchange(_head, _head->next);
37 }
38
39 private:
40 Node* _head = nullptr;
41};
42
43} // namespace yaclib::detail
Stack(const Stack &)=delete
Stack() noexcept=default
bool Empty() const noexcept
void PushFront(Node &node) noexcept
Stack & operator=(Stack &&)=delete
Stack & operator=(const Stack &)=delete
void PushBack(Node &node) noexcept
Node & PopFront() noexcept
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
Node class, used in intrusive data structure.
Definition node.hpp:8