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: ...@@ -116,8 +116,7 @@ public:
/// Applies `f` to each element in the queue, excluding cached elements. /// Applies `f` to each element in the queue, excluding cached elements.
template <class F> template <class F>
void peek_all(F f) const { void peek_all(F f) const {
for (auto i = list_.begin(); i != list_.end(); ++i) list_.peek_all(f);
f(*promote(i.ptr));
} }
// -- modifiers ------------------------------------------------------------- // -- modifiers -------------------------------------------------------------
......
...@@ -65,13 +65,6 @@ public: ...@@ -65,13 +65,6 @@ public:
return deficit_; 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 -------------------------------------------------------------- // -- modifiers --------------------------------------------------------------
void inc_deficit(deficit_type x) noexcept { void inc_deficit(deficit_type x) noexcept {
......
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
return false; return false;
do { do {
auto next = head->next; auto next = head->next;
queue_.lifo_append(promote(head)); queue_.lifo_append(lifo_inbox_type::promote(head));
head = next; head = next;
} while (head != nullptr); } while (head != nullptr);
queue_.stop_lifo_append(); queue_.stop_lifo_append();
......
...@@ -55,6 +55,13 @@ public: ...@@ -55,6 +55,13 @@ public:
using iterator_category = std::forward_iterator_tag; 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 ------------------------------------------------------- // -- member variables -------------------------------------------------------
node_pointer ptr; node_pointer ptr;
......
...@@ -35,6 +35,8 @@ namespace intrusive { ...@@ -35,6 +35,8 @@ namespace intrusive {
template <class Policy> template <class Policy>
class lifo_inbox { class lifo_inbox {
public: public:
// -- member types -----------------------------------------------------------
using policy_type = Policy; using policy_type = Policy;
using value_type = typename policy_type::mapped_type; using value_type = typename policy_type::mapped_type;
...@@ -49,6 +51,15 @@ public: ...@@ -49,6 +51,15 @@ public:
using deleter_type = typename unique_pointer::deleter_type; 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. /// Tries to enqueue a new element to the inbox.
/// @threadsafe /// @threadsafe
inbox_result push_front(pointer new_element) noexcept { inbox_result push_front(pointer new_element) noexcept {
......
...@@ -46,18 +46,5 @@ struct singly_linked { ...@@ -46,18 +46,5 @@ struct singly_linked {
node_pointer next; 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 intrusive
} // namespace caf } // namespace caf
...@@ -60,6 +60,13 @@ public: ...@@ -60,6 +60,13 @@ public:
using const_iterator = forward_iterator<const value_type>; 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 ------------------- // -- constructors, destructors, and assignment operators -------------------
task_queue(policy_type p) task_queue(policy_type p)
...@@ -128,6 +135,13 @@ public: ...@@ -128,6 +135,13 @@ public:
return ptr != &tail_ ? promote(ptr) : nullptr; 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 ------------------------------------------------------------- // -- modifiers -------------------------------------------------------------
/// Removes all elements from the queue. /// Removes all elements from the queue.
......
...@@ -77,7 +77,7 @@ struct fixture { ...@@ -77,7 +77,7 @@ struct fixture {
while (ptr != nullptr) { while (ptr != nullptr) {
auto next = ptr->next; auto next = ptr->next;
result += to_string(*ptr); result += to_string(*ptr);
ptr.reset(promote(next)); ptr.reset(inbox_type::promote(next));
} }
return result; 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