8#include "../object_model/read_only_collection.h"
9#include "../../argument_exception.h"
10#include "../../argument_out_of_range_exception.h"
11#include "../../index_out_of_range_exception.h"
12#include "../../box_integer.h"
13#include "../../invalid_operation_exception.h"
14#include "../../intptr.h"
16#include "../../literals.h"
17#include "../../object.h"
18#include "../../new_ptr.h"
20#include "../../string.h"
27 namespace collections {
71 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
144 template<
typename input_iterator_t>
312 virtual bool empty() const noexcept {
return data_->items.empty();}
409 template<
typename enumerable_t>
418 data_->items.assign(
count, value);
425 template<
typename input_iterator_t>
426 void assign(input_iterator_t first, input_iterator_t last) {
428 data_->items.assign(first, last);
441 for (
auto item :
items)
451 return reinterpret_cast<reference>(data_->items.at(index));
464 data_->items.clear();
467 bool contains(
const type_t& value)
const noexcept override {
468 for (
const type_t& item : data_->items)
469 if (item == value)
return true;
504 for (
const type_t& item : *
this) {
505 if (
i >= index +
count)
return;
507 array[array_index +
c] = item;
520 template<
typename... args_t>
523 return data_->items.eplace(std::forward<args_t>(args)...);
530 template<
typename... args_t>
533 return data_->items.emplace_back(std::forward<args_t>(args)...);
537 bool equals(
const list& rhs)
const noexcept override {
return data_->items == rhs.data_->items && data_->version == rhs.data_->version;}
548 return to_iterator(data_->items.erase(to_base_type_iterator(pos)));
560 return to_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
576 class list_enumerator :
public ienumerator<value_type> {
582 return items_.at(index_);
585 bool move_next()
override {
587 return ++index_ < items_.count();
590 void reset()
override {
591 version_ = items_.data_->version;
600 return {new_ptr<list_enumerator>(*
this, data_->version)};
646 for (
auto i = index;
i < index +
count; ++
i)
647 if (
at(
i) == value)
return i;
659 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
669 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
680 return to_iterator(data_->items.insert(to_base_type_iterator(pos),
count, value));
689 template<
typename input_iterator_t>
692 return to_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
702 return to_iterator(data_->items.insert(to_base_type_iterator(pos),
items.begin(),
items.end()));
752 template<
typename ienumerable_t>
758 auto items = list<type_t>(enumerable.begin(), enumerable.end());
763 insert(
begin() + index, enumerable.begin(), enumerable.end());
772 data_->items.pop_back();
781 data_->items.push_back(value);
789 data_->items.push_back(value);
792 bool remove(
const type_t& item)
override {
793 if (
count() == 0)
return false;
795 if (
at(index) != item)
continue;
847 data_->items.resize(
count, value);
859 data_->items.swap(
other.data_->items);
907 data_->version = std::move(
other.data_->version);
908 data_->items = std::move(
other.data_->items);
916 data_->items =
items;
933 virtual operator const base_type&()
const noexcept {
return data_->items;}
936 virtual operator base_type&()
noexcept {
return data_->items;}
940 typename base_type::iterator to_base_type_iterator(
iterator value)
noexcept {
941 if (value ==
begin())
return data_->items.begin();
942 if (value ==
end())
return data_->items.end();
943 return data_->items.begin() + (value -
begin());
946 iterator to_iterator(
typename base_type::iterator value)
noexcept {
947 if (value == data_->items.begin())
return begin();
948 if (value == data_->items.end())
return end();
949 return begin() + (value - data_->items.begin());
954 explicit data(
const allocator_type& alloc) noexcept : items(alloc) {}
957 template<
typename input_iterator_t>
960 data(
const list&
list) : items(
list.data_->items), version(
list.data_->version) {}
965 data(
list&&
other) : items(std::move(
other.data_->items)), version(std::move(
other.data_->version)) {
other.data_->items.clear();
other.data_->version = 0;}
970 data(
const data&) =
default;
971 data& operator =(
const data&) =
default;
984 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
985 list(std::initializer_list<type_t>) -> list<type_t, allocator_t>;
987 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
990 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
993 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
994 list(
const std::vector<type_t>&) -> list<type_t, allocator_t>;
996 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
997 list(
const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
999 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
1000 list(std::vector<type_t>&&) -> list<type_t, allocator_t>;
1002 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>
::type>>
1003 list(list<type_t, allocator_t>&&) -> list<type_t, allocator_t>;
Contains xtd::collections::generic::helpers::allocator alias.
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition argument_exception.h:23
The exception that is thrown when one of the arguments provided to a method is out of range.
Definition argument_out_of_range_exception.h:22
static basic_string join(const basic_string separator, const collection_t &values) noexcept
Concatenates a specified separator basic_string between each element of a specified object array,...
Definition basic_string.h:2178
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:209
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:205
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:213
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:198
Supports a simple iteration over a generic collection.
Definition enumerator.h:31
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.h:35
Supports a simple iteration over a generic collection.
Definition ienumerator.h:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.h:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:49
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:72
void insert(size_type index, const type_t &value) override
Inserts an element into the xtd::collections::generic::list <type_t> at the specified index.
Definition list.h:710
bool is_read_only() const noexcept override
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Definition list.h:331
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:304
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition list.h:336
virtual void swap(list &other) noexcept
Exchanges the contents and capacity of the container with those of other. Does not invoke any move,...
Definition list.h:857
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.h:386
virtual void push_back(type_t &&value)
Appends the given element value to the end of the container.
Definition list.h:787
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:449
list get_range(size_type index, size_type count)
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.h:615
list(base_type &&other)
Move constructor with specified base type list.
Definition list.h:180
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:205
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:457
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.h:536
virtual const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:299
virtual size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition list.h:343
virtual void copy_to(size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array,...
Definition list.h:501
virtual reference front()
Returns a reference to the first element in the container.
Definition list.h:324
const value_type * const_pointer
Represents the const pointer of list value type.
Definition list.h:94
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition list.h:367
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.h:111
virtual void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.h:893
virtual xtd::array< value_type > to_array() const noexcept
Copies the elements of the xtd::collections::generic::list <type_t> to a new array.
Definition list.h:869
list(std::initializer_list< type_t > items, const allocator_type &alloc=allocator_type())
Constructs the container with the contents of the specified initializer list, and allocator.
Definition list.h:173
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:316
virtual void insert_range(size_type index, const xtd::collections::generic::ienumerable< type_t > &enumerable)
Inserts copy of elements from a collection into the xtd::collections::generic::list <type_t> at the s...
Definition list.h:724
void remove_at(size_type index) override
Removes the element at the specified index of the xtd::collections::generic::list <type_t>.
Definition list.h:805
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.h:416
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:357
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.h:924
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:262
virtual void pop_back()
Removes the last element of the container.
Definition list.h:770
void assign(input_iterator_t first, input_iterator_t last)
Replaces the contents with copies of those in the range [first, last).
Definition list.h:426
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of list value type.
Definition list.h:100
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.h:184
void copy_to(xtd::array< type_t > &array, size_type array_index) const override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition list.h:485
virtual void copy_to(xtd::array< type_t > &array) const
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array.
Definition list.h:483
list(input_iterator_t first, input_iterator_t last, const allocator_type &alloc=allocator_type())
Constructs the container with the contents of the range [first, last).
Definition list.h:145
typename std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Represents the list base type.
Definition list.h:82
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:308
void clear() override
Removes all items from the xtd::collections::generic::icollection <type_t>.
Definition list.h:462
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.h:339
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.h:312
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.h:871
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.h:328
virtual base_type & get_base_type() noexcept
Returns the underlying base type.
Definition list.h:570
size_type index_of(const type_t &value) const noexcept override
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:624
reference emplace_back(args_t &&... args)
Appends a new element to the end of the container. The element is constructed through std::allocator_...
Definition list.h:531
typename xtd::collections::generic::helpers::allocator< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type > allocator_type
Represents the list allocator type.
Definition list.h:80
bool is_synchronized() const noexcept override
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
Definition list.h:332
list(const list &list)
Default copy constructor with specified list.
Definition list.h:158
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition list.h:86
list(const xtd::collections::generic::ienumerable< type_t > &collection, const allocator_type &alloc=allocator_type())
Initializes a new instance of the xtd::collections::generic::list <type_t> class that contains elemen...
Definition list.h:154
list() noexcept=default
Initializes a new instance of the xtd::collections::generic::list class that is empty.
virtual const_reference back() const
Returns a reference to the last element in the container.
Definition list.h:201
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.h:169
virtual void shrink_to_fit()
Requests the removal of unused capacity.
Definition list.h:853
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.h:165
bool is_fixed_size() const noexcept override
Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
Definition list.h:330
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition list.h:84
typename xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Represents the read only collection of of list.
Definition list.h:104
const value_type & const_reference
Represents the const reference of list value type.
Definition list.h:90
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:319
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.h:232
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.h:439
virtual const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:294
virtual allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition list.h:565
virtual void remove_range(size_type index, size_type count)
Removes a range of elements from the xtd::collections::generic::list <type_t>.
Definition list.h:820
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.h:289
virtual void reserve(size_type new_cap)
Increase the capacity of the vector (the total number of elements that the vector can hold without re...
Definition list.h:831
list(size_type count, const type_t &value, const allocator_type &alloc=allocator_type())
Constructs the container with specified count copies of elements with specified value.
Definition list.h:135
list(list &&other)
Move constructor with specified list.
Definition list.h:177
list & operator=(const list &other)=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
typename base_type::const_reverse_iterator const_reverse_iterator
Represents the const reverse iterator of list value type.
Definition list.h:102
virtual const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:361
value_type & reference
Represents the reference of list value type.
Definition list.h:88
virtual void insert_range(size_type index, const std::initializer_list< type_t > &items)
Inserts copy of elements from a collection into the xtd::collections::generic::list <type_t> at the s...
Definition list.h:746
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through a collection.
Definition list.h:575
void add_range(const xtd::collections::generic::ienumerable< type_t > &enumerable)
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.h:396
virtual void resize(size_type count, const value_type &value)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.h:843
read_only_collection as_read_only() const noexcept
Returns a read-only xtd::collections::object_model::read_only_collection <type_t> wrapper for the cur...
Definition list.h:435
virtual reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:348
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:208
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.h:255
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:365
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.h:657
virtual void resize(size_type count)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.h:837
virtual size_type index_of(const type_t &value, size_type index) const
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:634
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.h:161
virtual const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:352
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.h:188
void add_range(std::initializer_list< type_t > il)
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.h:406
value_type * pointer
Represents the pointer of list value type.
Definition list.h:92
virtual iterator erase(const_iterator first, const_iterator last)
Erases the specified elements from the container.
Definition list.h:558
virtual void push_back(const type_t &value)
Appends the given element value to the end of the container.
Definition list.h:779
virtual const base_type & get_base_type() const noexcept
Returns the underlying base type.
Definition list.h:573
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:266
virtual iterator insert(const_iterator pos, const std::initializer_list< type_t > &items)
Inserts elements at the specified location in the container.
Definition list.h:700
virtual iterator erase(const_iterator pos)
Erases the specified elements from the container.
Definition list.h:546
bool contains(const type_t &value) const noexcept override
Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
Definition list.h:467
type_t value_type
Represents the list value type.
Definition list.h:78
virtual size_type index_of(const type_t &value, size_type index, size_type count) const
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:642
iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last)
Inserts elements at the specified location in the container.
Definition list.h:690
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.h:521
bool remove(const type_t &item) override
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <ty...
Definition list.h:792
list(size_type count, const allocator_type &alloc=allocator_type())
Constructs the container with specified count default-inserted instances of type_t....
Definition list.h:139
typename xtd::collections::generic::ilist< type_t >::iterator iterator
Represents the iterator of list value type.
Definition list.h:96
virtual iterator insert(const_iterator pos, size_type count, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.h:678
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.h:667
typename xtd::collections::generic::ilist< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition list.h:98
virtual reference back()
Returns a reference to the last element in the container.
Definition list.h:197
Provides the base class for a generic read-only collection.
Definition read_only_collection.h:40
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
The exception that is thrown when an attempt is made to access an element of an array with an index t...
Definition index_out_of_range_exception.h:18
The exception that is thrown when a method call is invalid for the object's current state.
Definition invalid_operation_exception.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.h:35
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
size_t size
Represents a size of any object in bytes.
Definition size.h:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.h:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.h:23
std::type_info type
Stores information about a type.
Definition type.h:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.h:23
@ other
The operating system is other.
@ insert
The INS (INSERT) key.
Contains xtd::collections::ilist alias.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
std::vector< type_t > array
Definition __array_definition.h:18
Contains xtd::collections::generic::params class.