7#include "../object_model/read_only_collection.h"
8#include "../../argument_exception.h"
9#include "../../argument_out_of_range_exception.h"
10#include "../../index_out_of_range_exception.h"
11#include "../../box_integer.h"
12#include "../../invalid_operation_exception.h"
13#include "../../intptr.h"
15#include "../../literals.h"
16#include "../../object.h"
17#include "../../new_ptr.h"
19#include "../../string.h"
26 namespace collections {
70 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>>
143 template<
typename input_iterator_t>
311 virtual bool empty() const noexcept {
return data_->items.empty();}
408 template<
typename enumerable_t>
417 data_->items.assign(
count, value);
424 template<
typename input_iterator_t>
425 void assign(input_iterator_t first, input_iterator_t last) {
427 data_->items.assign(first, last);
440 for (
auto item :
items)
450 return reinterpret_cast<reference>(data_->items.at(index));
463 data_->items.clear();
466 bool contains(
const type_t& value)
const noexcept override {
467 for (
const auto& item : data_->items)
468 if (
reinterpret_cast<const type_t&
>(item) == value)
return true;
503 for (
const type_t& item : *
this) {
504 if (
i >= index +
count)
return;
506 array[array_index +
c] = item;
519 template<
typename... args_t>
522 return data_->items.eplace(std::forward<args_t>(args)...);
529 template<
typename... args_t>
532 return data_->items.emplace_back(std::forward<args_t>(args)...);
536 bool equals(
const list& rhs)
const noexcept override {
return data_->items == rhs.data_->items && data_->version == rhs.data_->version;}
547 return to_iterator(data_->items.erase(to_base_type_iterator(pos)));
559 return to_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
575 class list_enumerator :
public ienumerator<value_type> {
581 return items_.at(index_);
584 bool move_next()
override {
586 return ++index_ < items_.count();
589 void reset()
override {
590 version_ = items_.data_->version;
599 return {new_ptr<list_enumerator>(*
this, data_->version)};
645 for (
auto i = index;
i < index +
count; ++
i)
646 if (
at(
i) == value)
return i;
658 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
668 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
679 return to_iterator(data_->items.insert(to_base_type_iterator(pos),
count, value));
688 template<
typename input_iterator_t>
691 return to_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
701 return to_iterator(data_->items.insert(to_base_type_iterator(pos),
items.begin(),
items.end()));
751 template<
typename ienumerable_t>
757 auto items = list<type_t>(enumerable.begin(), enumerable.end());
762 insert(
begin() + index, enumerable.begin(), enumerable.end());
771 data_->items.pop_back();
780 data_->items.push_back(value);
788 data_->items.push_back(value);
791 bool remove(
const type_t& item)
override {
792 if (
count() == 0)
return false;
794 if (
at(index) != item)
continue;
846 data_->items.resize(
count, value);
858 data_->items.swap(
other.data_->items);
906 data_->version = std::move(
other.data_->version);
907 data_->items = std::move(
other.data_->items);
915 data_->items =
items;
932 operator const base_type&()
const noexcept {
return data_->items;}
939 typename base_type::iterator to_base_type_iterator(
iterator value)
noexcept {
940 if (value ==
begin())
return data_->items.begin();
941 if (value ==
end())
return data_->items.end();
942 return data_->items.begin() + (value -
begin());
945 iterator to_iterator(
typename base_type::iterator value)
noexcept {
946 if (value == data_->items.begin())
return begin();
947 if (value == data_->items.end())
return end();
948 return begin() + (value - data_->items.begin());
953 explicit data(
const allocator_type& alloc) noexcept : items(alloc) {}
956 template<
typename input_iterator_t>
959 data(
const list&
list) : items(
list.data_->items), version(
list.data_->version) {}
964 data(
list&&
other) : items(std::move(
other.data_->items)), version(std::move(
other.data_->version)) {
other.data_->items.clear();
other.data_->version = 0;}
969 data(
const data&) =
default;
970 data& operator =(
const data&) =
default;
983 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>>
984 list(std::initializer_list<type_t>) -> list<type_t, allocator_t>;
986 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>>
989 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>>
992 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 list(
const std::vector<type_t>&) -> list<type_t, allocator_t>;
995 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>>
996 list(
const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
998 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>>
999 list(std::vector<type_t>&&) -> list<type_t, allocator_t>;
1001 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>>
1002 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:24
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:23
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.h:58
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.h:211
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:2296
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:71
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:709
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:330
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:303
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition list.h:335
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:856
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.h:385
virtual void push_back(type_t &&value)
Appends the given element value to the end of the container.
Definition list.h:786
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:448
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:614
list(base_type &&other)
Move constructor with specified base type list.
Definition list.h:179
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:204
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:456
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.h:535
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:298
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:342
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:500
virtual reference front()
Returns a reference to the first element in the container.
Definition list.h:323
const value_type * const_pointer
Represents the const pointer of list value type.
Definition list.h:93
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:366
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.h:110
virtual void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.h:892
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:868
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:172
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:315
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:723
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:804
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.h:415
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:356
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.h:923
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:261
virtual void pop_back()
Removes the last element of the container.
Definition list.h:769
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:425
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of list value type.
Definition list.h:99
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.h:183
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:484
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:482
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:144
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:81
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:307
void clear() override
Removes all items from the xtd::collections::generic::icollection <type_t>.
Definition list.h:461
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.h:338
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.h:311
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.h:870
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.h:327
virtual base_type & get_base_type() noexcept
Returns the underlying base type.
Definition list.h:569
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:623
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:530
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:79
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:331
list(const list &list)
Default copy constructor with specified list.
Definition list.h:157
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition list.h:85
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:153
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:200
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.h:168
virtual void shrink_to_fit()
Requests the removal of unused capacity.
Definition list.h:852
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.h:164
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:329
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition list.h:83
typename xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Represents the read only collection of of list.
Definition list.h:103
const value_type & const_reference
Represents the const reference of list value type.
Definition list.h:89
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:318
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.h:231
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.h:438
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:293
virtual allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition list.h:564
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:819
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.h:288
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:830
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:134
list(list &&other)
Move constructor with specified list.
Definition list.h:176
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:101
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:360
value_type & reference
Represents the reference of list value type.
Definition list.h:87
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:745
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through a collection.
Definition list.h:574
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:395
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:842
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:434
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:347
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:207
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.h:254
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:364
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.h:656
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:836
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:633
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.h:160
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:351
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.h:187
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:405
value_type * pointer
Represents the pointer of list value type.
Definition list.h:91
virtual iterator erase(const_iterator first, const_iterator last)
Erases the specified elements from the container.
Definition list.h:557
virtual void push_back(const type_t &value)
Appends the given element value to the end of the container.
Definition list.h:778
virtual const base_type & get_base_type() const noexcept
Returns the underlying base type.
Definition list.h:572
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:265
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:699
virtual iterator erase(const_iterator pos)
Erases the specified elements from the container.
Definition list.h:545
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:466
type_t value_type
Represents the list value type.
Definition list.h:77
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:641
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:689
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.h:520
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:791
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:138
typename xtd::collections::generic::ilist< type_t >::iterator iterator
Represents the iterator of list value type.
Definition list.h:95
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:677
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.h:666
typename xtd::collections::generic::ilist< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition list.h:97
virtual reference back()
Returns a reference to the last element in the container.
Definition list.h:196
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:19
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition invalid_operation_exception.h:19
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
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:24
@ 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