Commit 36491961 authored by Dominik Charousset's avatar Dominik Charousset

removed unused class `singly_linked_list`

parent 746c69fb
cppa/detail/abstract_actor.hpp
cppa/event_based_actor.hpp
cppa/actor.hpp
cppa/actor_addressing.hpp
cppa/actor_companion_mixin.hpp
cppa/actor_proxy.hpp
cppa/announce.hpp
cppa/any_tuple.hpp
......@@ -12,40 +12,50 @@ cppa/binary_deserializer.hpp
cppa/binary_serializer.hpp
cppa/channel.hpp
cppa/config.hpp
cppa/context_switching_actor.hpp
cppa/cow_ptr.hpp
cppa/cow_tuple.hpp
cppa/cppa.hpp
cppa/cppa_fwd.hpp
cppa/deserializer.hpp
cppa/detail/abstract_actor.hpp
cppa/detail/abstract_scheduled_actor.hpp
cppa/detail/abstract_tuple.hpp
cppa/detail/actor_count.hpp
cppa/actor_addressing.hpp
cppa/detail/actor_registry.hpp
cppa/detail/atom_val.hpp
cppa/detail/behavior_impl.hpp
cppa/detail/behavior_stack.hpp
cppa/detail/boxed.hpp
cppa/detail/channel.hpp
cppa/detail/container_tuple_view.hpp
cppa/thread_mapped_actor.hpp
cppa/detail/decorated_names_map.hpp
cppa/detail/decorated_tuple.hpp
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/demangle.hpp
cppa/detail/disablable_delete.hpp
cppa/detail/empty_tuple.hpp
cppa/detail/event_based_actor_factory.hpp
cppa/detail/fd_util.hpp
cppa/detail/get_behavior.hpp
cppa/detail/group_manager.hpp
cppa/detail/implicit_conversions.hpp
cppa/detail/matches.hpp
cppa/detail/object_array.hpp
cppa/detail/object_impl.hpp
cppa/detail/opt_impls.hpp
cppa/detail/pair_member.hpp
cppa/detail/projection.hpp
cppa/detail/pseudo_tuple.hpp
cppa/detail/ptype_to_type.hpp
cppa/detail/receive_loop_helper.hpp
cppa/detail/receive_policy.hpp
cppa/detail/recursive_queue_node.hpp
cppa/detail/scheduled_actor_dummy.hpp
cppa/detail/serialize_tuple.hpp
cppa/detail/singleton_manager.hpp
cppa/detail/singleton_mixin.hpp
cppa/detail/stacked_actor_mixin.hpp
cppa/detail/swap_bytes.hpp
cppa/detail/tdata.hpp
cppa/detail/thread_pool_scheduler.hpp
......@@ -60,36 +70,62 @@ cppa/detail/unboxed.hpp
cppa/detail/uniform_type_info_map.hpp
cppa/detail/value_guard.hpp
cppa/detail/yield_interface.hpp
cppa/context_switching_actor.hpp
cppa/either.hpp
cppa/enable_weak_ptr_mixin.hpp
cppa/event_based_actor.hpp
cppa/exception.hpp
cppa/exit_reason.hpp
cppa/factory.hpp
cppa/from_string.hpp
cppa/sb_actor.hpp
cppa/get.hpp
cppa/group.hpp
cppa/guard_expr.hpp
cppa/intrusive/forward_iterator.hpp
cppa/intrusive/single_reader_queue.hpp
cppa/intrusive/singly_linked_list.hpp
cppa/intrusive_ptr.hpp
cppa/local_actor.hpp
cppa/logging.hpp
cppa/match.hpp
cppa/match_expr.hpp
cppa/message_future.hpp
cppa/message_id.hpp
cppa/network/acceptor.hpp
cppa/network/continuable_io.hpp
cppa/network/continuable_reader.hpp
cppa/network/default_actor_addressing.hpp
cppa/network/default_actor_proxy.hpp
cppa/network/default_message_queue.hpp
cppa/network/default_peer.hpp
cppa/network/default_peer_acceptor.hpp
cppa/network/default_protocol.hpp
cppa/network/input_stream.hpp
cppa/network/io_stream.hpp
cppa/network/ipv4_acceptor.hpp
cppa/network/ipv4_io_stream.hpp
cppa/network/message_header.hpp
cppa/network/middleman.hpp
cppa/network/middleman_event_handler_base.hpp
cppa/network/output_stream.hpp
cppa/network/protocol.hpp
cppa/object.hpp
cppa/on.hpp
cppa/opt.hpp
cppa/option.hpp
cppa/partial_function.hpp
cppa/primitive_type.hpp
cppa/primitive_variant.hpp
cppa/process_information.hpp
cppa/qtsupport/actor_widget_mixin.hpp
cppa/receive.hpp
cppa/ref_counted.hpp
cppa/response_handle.hpp
cppa/sb_actor.hpp
cppa/scheduled_actor.hpp
cppa/scheduler.hpp
cppa/scheduling_hint.hpp
cppa/self.hpp
cppa/serializer.hpp
cppa/thread_mapped_actor.hpp
cppa/timeout_definition.hpp
cppa/to_string.hpp
cppa/tpartial_function.hpp
cppa/tuple_cast.hpp
......@@ -138,44 +174,72 @@ cppa/util/type_pair.hpp
cppa/util/upgrade_lock_guard.hpp
cppa/util/void_type.hpp
cppa/util/wrapped.hpp
cppa/weak_intrusive_ptr.hpp
cppa/weak_ptr_anchor.hpp
cppa/wildcard_position.hpp
examples/announce_example_1.cpp
examples/announce_example_2.cpp
examples/announce_example_3.cpp
examples/announce_example_4.cpp
examples/announce_example_5.cpp
examples/dancing_kirby.cpp
examples/distributed_math_actor_example.cpp
examples/dining_philosophers.cpp
examples/distributed_math_actor_example.cpp
examples/group_chat.cpp
examples/group_server.cpp
examples/hello_world_example.cpp
examples/math_actor_example.cpp
src/event_based_actor.cpp
examples/type_plugins.hpp
src/abstract_tuple.cpp
src/actor.cpp
src/actor_addressing.cpp
src/actor_count.cpp
src/actor_proxy.cpp
src/actor_registry.cpp
src/any_tuple.cpp
src/atom.cpp
src/attachable.cpp
src/behavior_stack.cpp
src/binary_deserializer.cpp
src/binary_serializer.cpp
src/buffer.cpp
src/channel.cpp
src/thread_mapped_actor.cpp
src/context_switching_actor.cpp
src/continuable_reader.cpp
src/continuable_writer.cpp
src/decorated_names_map.cpp
src/default_actor_addressing.cpp
src/default_actor_proxy.cpp
src/default_peer.cpp
src/default_peer_acceptor.cpp
src/default_protocol.cpp
src/demangle.cpp
src/deserializer.cpp
src/duration.cpp
src/empty_tuple.cpp
src/event_based_actor.cpp
src/exception.cpp
src/factory.cpp
src/fd_util.cpp
src/fiber.cpp
src/group.cpp
src/group_manager.cpp
src/ipv4_acceptor.cpp
src/ipv4_io_stream.cpp
src/local_actor.cpp
src/logging.cpp
src/message_header.cpp
src/middleman.cpp
src/object.cpp
src/object_array.cpp
src/opt.cpp
src/partial_function.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/protocol.cpp
src/receive.cpp
src/ref_counted.cpp
src/response_handle.cpp
src/ripemd_160.cpp
src/scheduled_actor.cpp
src/scheduled_actor_dummy.cpp
......@@ -185,12 +249,13 @@ src/serializer.cpp
src/shared_spinlock.cpp
src/singleton_manager.cpp
src/string_serialization.cpp
src/thread_mapped_actor.cpp
src/thread_pool_scheduler.cpp
src/to_uniform_name.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp
src/context_switching_actor.cpp
unit_testing/ping_pong.cpp
unit_testing/ping_pong.hpp
unit_testing/test.hpp
......@@ -210,70 +275,3 @@ unit_testing/test__tuple.cpp
unit_testing/test__type_list.cpp
unit_testing/test__uniform_type.cpp
unit_testing/test__yield_interface.cpp
cppa/detail/receive_policy.hpp
cppa/detail/behavior_stack.hpp
src/behavior_stack.cpp
cppa/detail/stacked_actor_mixin.hpp
cppa/detail/event_based_actor_factory.hpp
cppa/factory.hpp
src/factory.cpp
cppa/message_id.hpp
cppa/cppa_fwd.hpp
cppa/timeout_definition.hpp
cppa/detail/behavior_impl.hpp
cppa/network/output_stream.hpp
cppa/network/input_stream.hpp
cppa/network/io_stream.hpp
cppa/network/acceptor.hpp
cppa/network/ipv4_io_stream.hpp
src/ipv4_io_stream.cpp
cppa/network/ipv4_acceptor.hpp
src/ipv4_acceptor.cpp
cppa/network/middleman.hpp
src/middleman.cpp
src/buffer.cpp
cppa/message_future.hpp
cppa/detail/fd_util.hpp
src/fd_util.cpp
examples/group_server.cpp
examples/group_chat.cpp
cppa/opt.hpp
src/opt.cpp
cppa/detail/opt_impls.hpp
examples/type_plugins.hpp
cppa/detail/decorated_names_map.hpp
src/decorated_names_map.cpp
cppa/network/continuable_reader.hpp
src/continuable_reader.cpp
cppa/network/default_peer.hpp
src/default_peer.cpp
cppa/network/default_peer_acceptor.hpp
src/default_peer_acceptor.cpp
src/ref_counted.cpp
cppa/enable_weak_ptr_mixin.hpp
cppa/weak_intrusive_ptr.hpp
cppa/network/default_actor_proxy.hpp
src/default_actor_proxy.cpp
cppa/network/default_actor_addressing.hpp
src/default_actor_addressing.cpp
cppa/network/protocol.hpp
src/protocol.cpp
cppa/network/default_protocol.hpp
src/default_protocol.cpp
cppa/logging.hpp
src/logging.cpp
cppa/network/continuable_io.hpp
src/continuable_writer.cpp
cppa/network/middleman_event_handler_base.hpp
src/actor_addressing.cpp
cppa/weak_ptr_anchor.hpp
src/weak_ptr_anchor.cpp
cppa/actor_companion_mixin.hpp
cppa/detail/singleton_mixin.hpp
cppa/response_handle.hpp
src/response_handle.cpp
cppa/wildcard_position.hpp
cppa/network/message_header.hpp
src/message_header.cpp
cppa/qtsupport/actor_widget_mixin.hpp
cppa/network/default_message_queue.hpp
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_FORWARD_ITERATOR_HPP
#define CPPA_FORWARD_ITERATOR_HPP
#include <iterator>
namespace cppa { namespace intrusive {
/**
* @brief A forward iterator for intrusive lists.
*/
template<class T>
class forward_iterator {
public:
typedef T value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category;
inline forward_iterator(pointer ptr = nullptr) : m_ptr(ptr) { }
forward_iterator(const forward_iterator&) = default;
forward_iterator& operator=(const forward_iterator&) = default;
inline forward_iterator& operator++() {
m_ptr = m_ptr->next;
return *this;
}
inline forward_iterator operator++(int) {
forward_iterator tmp{*this};
m_ptr = m_ptr->next;
return tmp;
}
inline explicit operator bool() { return m_ptr != nullptr; }
inline bool operator!() { return m_ptr != nullptr; }
inline reference operator*() { return *m_ptr; }
inline const_reference operator*() const { return *m_ptr; }
inline pointer operator->() { return m_ptr; }
inline const_pointer operator->() const { return m_ptr; }
/**
* @brief Returns the element this iterator points to.
*/
inline pointer ptr() { return m_ptr; }
/**
* @brief Returns the element this iterator points to.
*/
inline const_pointer ptr() const { return m_ptr; }
private:
pointer m_ptr;
};
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator==(const forward_iterator<T>& lhs,
const forward_iterator<T>& rhs) {
return lhs.ptr() == rhs.ptr();
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator==(const forward_iterator<T>& lhs, const T* rhs) {
return lhs.ptr() == rhs;
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator==(const T* lhs, const forward_iterator<T>& rhs) {
return lhs == rhs.ptr();
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator==(const forward_iterator<T>& lhs, std::nullptr_t) {
return lhs.ptr() == nullptr;
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator==(std::nullptr_t, const forward_iterator<T>& rhs) {
return rhs.ptr() == nullptr;
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator!=(const forward_iterator<T>& lhs,
const forward_iterator<T>& rhs) {
return !(lhs == rhs);
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator!=(const forward_iterator<T>& lhs, const T* rhs) {
return !(lhs == rhs);
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator!=(const T* lhs, const forward_iterator<T>& rhs) {
return !(lhs == rhs);
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator!=(const forward_iterator<T>& lhs, std::nullptr_t) {
return !(lhs == nullptr);
}
/**
* @relates forward_iterator
*/
template<class T>
inline bool operator!=(std::nullptr_t, const forward_iterator<T>& rhs) {
return !(nullptr == rhs);
}
} } // namespace cppa::intrusive
#endif // CPPA_FORWARD_ITERATOR_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_SINGLY_LINKED_LIST_HPP
#define CPPA_SINGLY_LINKED_LIST_HPP
#include <cstddef>
#include <utility>
#include "cppa/config.hpp"
#include "cppa/intrusive/forward_iterator.hpp"
namespace cppa { namespace intrusive {
/**
* @brief A singly linked list similar to std::forward_list
* but intrusive and with push_back() support.
* @tparam T A class providing a @p next pointer and a default constructor.
*/
template<class T>
class singly_linked_list {
singly_linked_list(const singly_linked_list&) = delete;
singly_linked_list& operator=(const singly_linked_list&) = delete;
public:
typedef T value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef forward_iterator<value_type> iterator;
typedef forward_iterator<value_type const> const_iterator;
singly_linked_list() : m_head(), m_tail(&m_head) { }
singly_linked_list(singly_linked_list&& other) : m_head(), m_tail(&m_head) {
*this = std::move(other);
}
singly_linked_list& operator=(singly_linked_list&& other) {
clear();
if (other.not_empty()) {
m_head.next = other.m_head.next;
m_tail = other.m_tail;
other.m_head.next = nullptr;
other.m_tail = &(other.m_head);
}
return *this;
}
/**
* @brief Creates a list from given [first, last] range.
*/
static singly_linked_list from(const std::pair<pointer, pointer>& p) {
singly_linked_list result;
result.m_head.next = p.first;
result.m_tail = p.second;
return result;
}
~singly_linked_list() { clear(); }
// element access
inline reference front() { return *(m_head.next); }
inline const_reference front() const { return *(m_head.next); }
inline reference back() { return *m_tail; }
inline const_reference back() const { return *m_tail; }
// iterators
inline iterator before_begin() { return &m_head; }
inline const_iterator before_begin() const { return &m_head; }
inline const_iterator cbefore_begin() const { return &m_head; }
inline iterator begin() { return m_head.next; }
inline const_iterator begin() const { return m_head.next; }
inline const_iterator cbegin() const { return m_head.next; }
inline iterator before_end() { return m_tail; }
inline const_iterator before_end() const { return m_tail; }
inline const_iterator cbefore_end() const { return m_tail; }
inline iterator end() { return nullptr; }
inline const_iterator end() const { return nullptr; }
inline const_iterator cend() const { return nullptr; }
// capacity
/**
* @brief Returns true if <tt>{@link begin()} == {@link end()}</tt>.
*/
inline bool empty() const { return m_head.next == nullptr; }
/**
* @brief Returns true if <tt>{@link begin()} != {@link end()}</tt>.
*/
inline bool not_empty() const { return m_head.next != nullptr; }
// no size member function because it would have O(n) complexity
// modifiers
/**
* @brief Deletes all elements.
* @post {@link empty()}
*/
void clear() {
if (not_empty()) {
auto h = m_head.next;
while (h) {
pointer next = h->next;
delete h;
h = next;
}
m_head.next = nullptr;
m_tail = &m_head;
}
}
/**
* @brief Inserts @p what after @p pos.
* @returns An iterator to the inserted element.
*/
iterator insert_after(iterator pos, pointer what) {
what->next = pos->next;
pos->next = what;
if (pos == m_tail) m_tail = what;
return what;
}
/**
* @brief Constructs an element from @p args in-place after @p pos.
* @returns An iterator to the inserted element.
*/
template<typename... Args>
void emplace_after(iterator pos, Args&&... args) {
insert_after(pos, new value_type(std::forward<Args>(args)...));
}
/**
* @brief Deletes the element after @p pos.
* @returns An iterator to the element following the erased one.
*/
iterator erase_after(iterator pos) {
CPPA_REQUIRE(pos != nullptr);
auto next = pos->next;
if (next) {
if (next == m_tail) m_tail = pos.ptr();
pos->next = next->next;
delete next;
}
return pos->next;
}
/**
* @brief Removes the element after @p pos from the list and returns it.
*/
pointer take_after(iterator pos) {
CPPA_REQUIRE(pos != nullptr);
auto next = pos->next;
if (next) {
if (next == m_tail) m_tail = pos.ptr();
pos->next = next->next;
next->next = nullptr;
}
return next;
}
/**
* @brief Appends @p what to the list.
*/
void push_back(pointer what) {
what->next = nullptr;
m_tail->next = what;
m_tail = what;
}
/**
* @brief Creates an element from @p args in-place and appends it
* to the list.
*/
template<typename... Args>
void emplace_back(Args&&... args) {
push_back(new value_type(std::forward<Args>(args)...));
}
/**
* @brief Inserts @p what as the first element of the list.
*/
void push_front(pointer what) {
if (empty()) {
push_back(what);
}
else {
what->next = m_head.next;
m_head.next = what;
}
}
/**
* @brief Creates an element from @p args and inserts it
* as the first element of the list.
*/
template<typename... Args>
void emplace_front(Args&&... args) {
push_front(new value_type(std::forward<Args>(args)...));
}
/**
* @brief Deletes the first element of the list.
*/
void pop_front() {
auto x = m_head.next;
if (x == nullptr) {
// list is empty
return;
}
else if (x == m_tail) {
m_tail = &m_head;
m_head.next = nullptr;
}
else {
m_head.next = x->next;
}
delete x;
}
// pop_back would have complexity O(n)
/**
* @brief Returns the content of the list as [first, last] sequence.
* @post {@link empty()}
*/
std::pair<pointer, pointer> take() {
if (empty()) {
return {nullptr, nullptr};
}
else {
auto result = std::make_pair(m_head.next, m_tail);
m_head.next = nullptr;
m_tail = &m_head;
return result;
}
}
/**
* @brief Moves all elements from @p other to @p *this.
* The elements are inserted after @p pos.
* @pre <tt>@p pos != {@link end()}</tt>
* @pre <tt>this != &other</tt>
*/
void splice_after(iterator pos, singly_linked_list&& other) {
CPPA_REQUIRE(pos != nullptr);
CPPA_REQUIRE(this != &other);
if (other.not_empty()) {
auto next = pos->next;
auto pair = other.take();
pos->next = pair.first;
pair.second->next = next;
if (pos == m_tail) {
CPPA_REQUIRE(next == nullptr);
m_tail = pair.second;
}
}
}
/**
* @brief Removes all elements for which predicate @p p returns @p true.
*/
template<typename UnaryPredicate>
void remove_if(UnaryPredicate p) {
auto i = before_begin();
while (i->next != nullptr) {
if (p(*(i->next))) { (void) erase_after(i);
}
else {
++i;
}
}
}
/**
* @brief Removes the first element for which predicate @p p
* returns @p true.
* @returns iterator to the element that preceded the removed element
* or end().
*/
template<typename UnaryPredicate>
iterator remove_first(UnaryPredicate p, iterator before_first) {
CPPA_REQUIRE(before_first != end());
while (before_first->next != nullptr) {
if (p(*(before_first->next))) {
erase_after(before_first);
return before_first;
}
else {
++before_first;
}
}
return end();
}
template<typename UnaryPredicate>
inline iterator remove_first(UnaryPredicate p) {
return remove_first(std::move(p), before_begin());
}
/**
* @brief Removes all elements that are equal to @p value.
*/
void remove(const value_type& value) {
remove_if([&](const value_type& other) { return value == other; });
}
private:
value_type m_head;
pointer m_tail;
};
} } // namespace cppa::intrusive
#endif // CPPA_SINGLY_LINKED_LIST_HPP
......@@ -49,8 +49,6 @@
#include "cppa/intrusive_ptr.hpp"
#include "cppa/detail/abstract_actor.hpp"
#include "cppa/intrusive/singly_linked_list.hpp"
#include "cppa/detail/receive_policy.hpp"
#include "cppa/detail/behavior_stack.hpp"
#include "cppa/detail/stacked_actor_mixin.hpp"
......
......@@ -31,7 +31,6 @@
#include <iterator>
#include "test.hpp"
#include "cppa/intrusive/singly_linked_list.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
using std::begin;
......@@ -58,68 +57,18 @@ inline bool operator==(int lhs, const iint& rhs) {
return lhs == rhs.value;
}
typedef cppa::intrusive::singly_linked_list<iint> iint_list;
typedef cppa::intrusive::single_reader_queue<iint> iint_queue;
int main() {
CPPA_TEST(test__intrusive_containers);
iint_list ilist1;
ilist1.push_back(new iint(1));
ilist1.emplace_back(2);
ilist1.push_back(new iint(3)); {
iint_list tmp;
tmp.push_back(new iint(4));
tmp.push_back(new iint(5));
ilist1.splice_after(ilist1.before_end(), std::move(tmp));
CPPA_CHECK(tmp.empty());
}
int iarr1[] = { 1, 2, 3, 4, 5 };
CPPA_CHECK((std::equal(begin(iarr1), end(iarr1), begin(ilist1))));
CPPA_CHECK((std::equal(begin(ilist1), end(ilist1), begin(iarr1))));
ilist1.push_front(new iint(0));
auto i = ilist1.erase_after(ilist1.begin());
// i points to second element
CPPA_CHECK_EQUAL(i->value, 2);
i = ilist1.insert_after(i, new iint(20));
CPPA_CHECK_EQUAL(i->value, 20);
int iarr2[] = { 0, 2, 20, 3, 4, 5 };
CPPA_CHECK((std::equal(begin(iarr2), end(iarr2), begin(ilist1))));
auto p = ilist1.take();
CPPA_CHECK(ilist1.empty());
auto ilist2 = iint_list::from(p);
ilist2.emplace_front(1); // 1 0 2 20 3 4 5
i = ilist2.erase_after(ilist2.begin()); // 1 2 20 3 4 5
CPPA_CHECK_EQUAL(i->value, 2);
ilist2.erase_after(i); // 1 2 3 4 5
CPPA_CHECK((std::equal(begin(iarr1), end(iarr1), begin(ilist2))));
// five elements + two dummies
CPPA_CHECK_EQUAL(s_iint_instances, 7);
ilist2.remove_if([](const iint& val) { return (val.value % 2) != 0; });
// two elements + two dummies
CPPA_CHECK_EQUAL(s_iint_instances, 4);
int iarr3[] = { 2, 4 };
CPPA_CHECK((std::equal(begin(iarr3), end(iarr3), begin(ilist2))));
auto xy = ilist2.take_after(ilist2.before_begin());
CPPA_CHECK_EQUAL(xy->value, 2);
delete xy;
ilist2.clear();
// two dummies
CPPA_CHECK_EQUAL(s_iint_instances, 2);
CPPA_CHECK(ilist2.empty());
cppa::intrusive::single_reader_queue<iint> q;
q.push_back(new iint(1));
q.push_back(new iint(2));
q.push_back(new iint(3));
CPPA_CHECK_EQUAL(s_iint_instances, 3);
auto x = q.pop();
CPPA_CHECK_EQUAL(1, x->value);
delete x;
......
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