50 template<
class type_t,
class allocator_t>
57 using value_type =
typename icollection<type_t>::value_type;
59 using base_type = std::list<value_type, allocator_t>;
93 linked_list(
const xtd::collections::generic::ienumerable < type_t >& collection) {
94 for (
const auto& item : collection)
100 for (
const auto& item :
items)
106 template < std::input_iterator input_iterator_t >
108 for (
auto iterator =
first; iterator !=
last; ++iterator)
182 auto iterator = node.data_->iterator;
183 if (iterator != data_->items.end()) ++iterator;
184 auto result = data_->items.insert(iterator, std::move(*new_node.data_->value));
186 new_node = {
self_, result, data_->version};
211 auto iterator = node.data_->iterator;
212 auto result = data_->items.insert(iterator, std::move(*new_node.data_->value));
214 new_node = {
self_, result, data_->version};
233 data_->items.push_front(node.data_->value.value());
235 node = {
self_, data_->items.begin(), data_->version};
254 data_->items.push_back(node.data_->value.value());
256 auto tmp = data_->items.end();
257 node = {
self_, --tmp, data_->version};
265 data_->items.clear();
272 auto contains(
const type_t& value)
const noexcept ->
bool override {
273 for (
const auto& item : data_->items)
287 for (
const auto& item : data_->items)
288 array[array_index++] = item;
297 for (
auto node =
first(); node; node = node->next())
308 for (
auto node =
last(); node; node = node->previous())
316 struct linked_list_enumerator :
public ienumerator < value_type > {
325 bool move_next()
override {
327 if (index_++ && iterator_ != items_.data_->items.cend()) ++iterator_;
328 else iterator_ = items_.data_->items.cbegin();
329 return iterator_ != items_.data_->items.cend();
332 void reset()
override {
334 version_ = items_.data_->version;
335 iterator_ = items_.data_->items.cend();
341 typename base_type::const_iterator iterator_ = items_.data_->items.cend();
352 auto remove(
const type_t& item)
noexcept ->
bool override {
353 auto node =
find(item);
354 if (node ==
nullopt)
return false;
366 node.data_->value = *node.data_->iterator;
367 data_->items.erase(node.data_->iterator);
369 node.data_->list =
null;
377 data_->items.erase(data_->items.begin());
386 data_->items.erase(--data_->items.end());
392 auto to_string() const noexcept ->
xtd::
string override {
return xtd::string::format(
"[{}]", xtd::string::join(
", ",
self_));}
406 data_->items = std::move(
other.data_->items);
413 data_->items =
items;
419 operator const base_type& ()
const noexcept {
return data_->items;}
427 auto add(
const type_t& item) ->
void override {
add_last(item);}
428 auto is_read_only() const noexcept ->
bool override {
return false;}
429 auto is_synchronized() const noexcept ->
bool override {
return false;}
430 const xtd::object& sync_root() const noexcept
override {
return data_->sync_root;}
432 struct linked_list_data {
434 xtd::object sync_root;
444 template <
class type_t,
class allocator_t = xtd::collections::
generic::helpers::allocator < type_t>>
445 linked_list(linked_list < type_t, allocator_t >&&) -> linked_list < type_t, allocator_t >;
447 template <
class type_t,
class allocator_t = xtd::collections::
generic::helpers::allocator < type_t>>
448 linked_list(
const list < type_t, allocator_t >&) -> linked_list < type_t, allocator_t >;
450 template <
class type_t>
451 linked_list(
const std::list < type_t >&) -> linked_list < type_t >;
453 template <
class type_t>
454 linked_list(std::list < type_t >&&) -> linked_list < type_t >;
456 template <
class type_t>
459 template <
class type_t>
460 linked_list(std::initializer_list < type_t >) -> linked_list < type_t >;
462 template <
class input_iterator_t>
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual size_type length() const noexcept
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:124
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a node in a LinkedList<T>. This class cannot be inherited.
Definition linked_list_node.hpp:43
Represents a doubly linked list.
Definition linked_list.hpp:51
linked_list(std::initializer_list< type_t > items)
Constructs the container with the contents of the specified initializer list, and allocator.
Definition linked_list.hpp:99
auto first() noexcept -> xtd::optional< linked_list_node< type_t > >
Gets the first node of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:132
linked_list(const xtd::collections::generic::ienumerable< type_t > &collection)
Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that contains...
Definition linked_list.hpp:93
auto find_last(const type_t value) const noexcept -> xtd::optional< linked_list_node< type_t > >
Finds the last node that contains the specified value.
Definition linked_list.hpp:307
auto add_last(const type_t &value) -> linked_list_node< type_t >
Adds a new node containing the specified value at the end of the xtd::collections::generic::linked_li...
Definition linked_list.hpp:242
linked_list()=default
Initializes a new instance of the xtd::collections::generic::linked_list <type_t> class that is empty...
std::list< value_type, allocator_t > base_type
Represents the list base type.
Definition linked_list.hpp:59
linked_list(const linked_list &list)
Default copy constructor with specified list.
Definition linked_list.hpp:81
auto remove_first() -> void
Removes the node at the start of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:375
auto add_after(const linked_list_node< type_t > &node, linked_list_node< type_t > &new_node) -> void
Adds the specified new node after the specified existing node in the xtd::collections::generic::linke...
Definition linked_list.hpp:178
auto last() noexcept -> xtd::optional< linked_list_node< type_t > >
Gets the last node of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:154
auto add_before(const linked_list_node< type_t > &node, linked_list_node< type_t > &new_node) -> void
Adds the specified new node before the specified existing node in the xtd::collections::generic::link...
Definition linked_list.hpp:207
auto clear() -> void override
Removes all elements from the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:264
auto add_last(linked_list_node< type_t > &node) -> void
Adds the specified new node at the end of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:252
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
Definition linked_list.hpp:392
auto operator=(const linked_list &other) -> linked_list &=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
auto remove(const type_t &item) noexcept -> bool override
Removes the first occurrence of a specific object from the xtd::collections::generic::linked_list <ty...
Definition linked_list.hpp:352
linked_list(input_iterator_t first, input_iterator_t last)
Constructs the container with the contents of the range [first, last).
Definition linked_list.hpp:107
linked_list(linked_list &&list)=default
Move constructor with specified list.
auto last() const noexcept -> xtd::optional< linked_list_node< value_type > >
Definition linked_list.hpp:148
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition linked_list.hpp:61
auto copy_to(xtd::array< type_t > &array, size_type array_index) const -> void override
Copies the entire xtd::colllections::generic::linked_list <type_t> to a compatible one-dimensional ar...
Definition linked_list.hpp:285
auto remove(linked_list_node< type_t > &node) -> void
Removes the specified node from the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:362
linked_list(base_type &&list)
Move constructor with specified base type list.
Definition linked_list.hpp:84
auto first() const noexcept -> xtd::optional< linked_list_node< value_type > >
Definition linked_list.hpp:126
typename icollection< type_t >::value_type value_type
Represents the list value type.
Definition linked_list.hpp:57
auto contains(const type_t &value) const noexcept -> bool override
Determines whether an element is in the xtd::colllections::generic::linked_list <type_t>.
Definition linked_list.hpp:272
auto add_first(linked_list_node< type_t > &node) -> void
Adds the specified new node at the start of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:231
auto items() noexcept -> base_type &
Returns the underlying base type items.
Definition linked_list.hpp:141
auto add_first(const type_t &value) -> linked_list_node< type_t >
Adds a new node containing the specified value at the start of the xtd::collections::generic::linked_...
Definition linked_list.hpp:221
auto count() const noexcept -> size_type override
Gets the number of nodes actually contained in the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:119
const value_type & const_reference
Represents the const reference of list value type.
Definition linked_list.hpp:65
auto add_after(const linked_list_node< type_t > &node, const type_t &value) -> linked_list_node< type_t >
Adds a new node containing the specified value after the specified existing node in the xtd::collecti...
Definition linked_list.hpp:167
auto items() const noexcept -> const base_type &
Definition linked_list.hpp:137
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:315
linked_list(const base_type &list)
Copy constructor with specified base type list.
Definition linked_list.hpp:87
auto add_before(const linked_list_node< type_t > &node, const type_t &value) -> linked_list_node< type_t >
Adds a new node containing the specified value before the specified existing node in the xtd::collect...
Definition linked_list.hpp:196
auto find(const type_t value) const noexcept -> xtd::optional< linked_list_node< type_t > >
Finds the first node that contains the specified value.
Definition linked_list.hpp:296
value_type & reference
Represents the reference of list value type.
Definition linked_list.hpp:63
auto remove_last() -> void
Removes the node at the end of the xtd::collections::generic::linked_list <type_t>.
Definition linked_list.hpp:384
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:115
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::icollection <type_t> interface.
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:65
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
null_ptr null
Represents a null pointer value.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:25
constexpr null_opt nullopt
Represents a nullopt value. Used to indicate that an std::optional does not contain a value.
Definition nullopt.hpp:26
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ other
The operating system is other.
Definition platform_id.hpp:60
@ add
The Add key.
Definition console_key.hpp:170
Contains xtd::collections::generic::linked_list_node <type_t> class.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::collections::object_model::read_only_collection class.
Contains xtd::string alias.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:39