Commit 1d73fb39 authored by Dominik Charousset's avatar Dominik Charousset

Always promote node pointers to the full type

parent b53a25ea
......@@ -116,8 +116,7 @@ public:
/// Applies `f` to each element in the queue, excluding cached elements.
template <class F>
void peek_all(F f) const {
for (auto i = list_.begin(); i != list_.end(); ++i)
f(*promote(i.ptr));
list_.peek_all(f);
}
// -- modifiers -------------------------------------------------------------
......
......@@ -65,13 +65,6 @@ public:
return deficit_;
}
/// Applies `f` to each element in the queue.
template <class F>
void peek_all(F f) const {
for (auto i = super::begin(); i != super::end(); ++i)
f(*promote(i.ptr));
}
// -- modifiers --------------------------------------------------------------
void inc_deficit(deficit_type x) noexcept {
......
......@@ -140,7 +140,7 @@ public:
return false;
do {
auto next = head->next;
queue_.lifo_append(promote(head));
queue_.lifo_append(lifo_inbox_type::promote(head));
head = next;
} while (head != nullptr);
queue_.stop_lifo_append();
......
......@@ -55,6 +55,13 @@ public:
using iterator_category = std::forward_iterator_tag;
// -- static utility functions -----------------------------------------------
/// Casts a node type to its value type.
static pointer promote(node_pointer ptr) noexcept {
return static_cast<pointer>(ptr);
}
// -- member variables -------------------------------------------------------
node_pointer ptr;
......
......@@ -35,6 +35,8 @@ namespace intrusive {
template <class Policy>
class lifo_inbox {
public:
// -- member types -----------------------------------------------------------
using policy_type = Policy;
using value_type = typename policy_type::mapped_type;
......@@ -49,6 +51,15 @@ public:
using deleter_type = typename unique_pointer::deleter_type;
// -- static utility functions -----------------------------------------------
/// Casts a node type to its value type.
static pointer promote(node_pointer ptr) noexcept {
return static_cast<pointer>(ptr);
}
// -- modifiers --------------------------------------------------------------
/// Tries to enqueue a new element to the inbox.
/// @threadsafe
inbox_result push_front(pointer new_element) noexcept {
......
......@@ -46,18 +46,5 @@ struct singly_linked {
node_pointer next;
};
/// Casts a node type to its value type.
template <class T>
T* promote(singly_linked<T>* ptr) {
return static_cast<T*>(ptr);
}
/// Casts a node type to its value type.
template <class T>
const T* promote(const singly_linked<T>* ptr) {
return static_cast<const T*>(ptr);
}
} // namespace intrusive
} // namespace caf
......@@ -60,6 +60,13 @@ public:
using const_iterator = forward_iterator<const value_type>;
// -- static utility functions -----------------------------------------------
/// Casts a node type to its value type.
static pointer promote(node_pointer ptr) noexcept {
return static_cast<pointer>(ptr);
}
// -- constructors, destructors, and assignment operators -------------------
task_queue(policy_type p)
......@@ -128,6 +135,13 @@ public:
return ptr != &tail_ ? promote(ptr) : nullptr;
}
/// Applies `f` to each element in the queue.
template <class F>
void peek_all(F f) const {
for (auto i = begin(); i != end(); ++i)
f(*i);
}
// -- modifiers -------------------------------------------------------------
/// Removes all elements from the queue.
......
......@@ -77,7 +77,7 @@ struct fixture {
while (ptr != nullptr) {
auto next = ptr->next;
result += to_string(*ptr);
ptr.reset(promote(next));
ptr.reset(inbox_type::promote(next));
}
return result;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment