7#include "../object_model/read_only_collection.hpp"
8#include "../../argument_exception.hpp"
9#include "../../argument_out_of_range_exception.hpp"
10#include "../../index_out_of_range_exception.hpp"
11#include "../../box_integer.hpp"
12#include "../../invalid_operation_exception.hpp"
13#include "../../intptr.hpp"
14#include "../../is.hpp"
15#include "../../literals.hpp"
16#include "../../object.hpp"
17#include "../../new_ptr.hpp"
18#include "../../ptr.hpp"
19#include "../../string.hpp"
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());
952 list_data() =
default;
953 explicit list_data(
const allocator_type& alloc) noexcept : items(alloc) {}
956 template<
typename input_iterator_t>
959 list_data(
const list&
list) : items(
list.data_->items), version(
list.data_->version) {}
964 list_data(
list&&
other) : items(std::move(
other.data_->items)), version(std::move(
other.data_->version)) {
other.data_->items.clear();
other.data_->version = 0;}
969 list_data(
const list_data&) =
default;
970 list_data& operator =(
const list_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.hpp: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.hpp:23
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp: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.hpp: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.hpp:2296
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.hpp:209
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:205
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.hpp:213
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:198
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:31
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:35
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.hpp:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.hpp:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.hpp:49
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp: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.hpp: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.hpp:330
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:303
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition list.hpp: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.hpp:856
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:385
virtual void push_back(type_t &&value)
Appends the given element value to the end of the container.
Definition list.hpp:786
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp: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.hpp:614
list(base_type &&other)
Move constructor with specified base type list.
Definition list.hpp:179
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:204
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:456
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.hpp: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.hpp: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.hpp: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.hpp:500
virtual reference front()
Returns a reference to the first element in the container.
Definition list.hpp:323
const value_type * const_pointer
Represents the const pointer of list value type.
Definition list.hpp: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.hpp:366
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.hpp:110
virtual void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.hpp: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.hpp: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.hpp:172
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp: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.hpp: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.hpp:804
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.hpp:415
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.hpp:356
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.hpp:923
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:261
virtual void pop_back()
Removes the last element of the container.
Definition list.hpp: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.hpp:425
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of list value type.
Definition list.hpp:99
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.hpp: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.hpp: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.hpp: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.hpp: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.hpp:81
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:307
void clear() override
Removes all items from the xtd::collections::generic::icollection <type_t>.
Definition list.hpp:461
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.hpp:338
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.hpp:311
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.hpp:870
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.hpp:327
virtual base_type & get_base_type() noexcept
Returns the underlying base type.
Definition list.hpp: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.hpp: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.hpp: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.hpp: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.hpp:331
list(const list &list)
Default copy constructor with specified list.
Definition list.hpp:157
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition list.hpp: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.hpp: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.hpp:200
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.hpp:168
virtual void shrink_to_fit()
Requests the removal of unused capacity.
Definition list.hpp:852
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.hpp: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.hpp:329
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition list.hpp:83
typename xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Represents the read only collection of of list.
Definition list.hpp:103
const value_type & const_reference
Represents the const reference of list value type.
Definition list.hpp:89
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp:318
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:231
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.hpp: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.hpp:293
virtual allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition list.hpp: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.hpp:819
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp: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.hpp: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.hpp:134
list(list &&other)
Move constructor with specified list.
Definition list.hpp: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.hpp: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.hpp:360
value_type & reference
Represents the reference of list value type.
Definition list.hpp: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.hpp:745
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through a collection.
Definition list.hpp: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.hpp: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.hpp: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.hpp: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.hpp:347
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:207
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp: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.hpp:364
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.hpp: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.hpp: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.hpp:633
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.hpp: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.hpp:351
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.hpp: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.hpp:405
value_type * pointer
Represents the pointer of list value type.
Definition list.hpp:91
virtual iterator erase(const_iterator first, const_iterator last)
Erases the specified elements from the container.
Definition list.hpp:557
virtual void push_back(const type_t &value)
Appends the given element value to the end of the container.
Definition list.hpp:778
virtual const base_type & get_base_type() const noexcept
Returns the underlying base type.
Definition list.hpp:572
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp: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.hpp:699
virtual iterator erase(const_iterator pos)
Erases the specified elements from the container.
Definition list.hpp: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.hpp:466
type_t value_type
Represents the list value type.
Definition list.hpp: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.hpp: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.hpp:689
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.hpp: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.hpp: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.hpp:138
typename xtd::collections::generic::ilist< type_t >::iterator iterator
Represents the iterator of list value type.
Definition list.hpp: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.hpp:677
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:666
typename xtd::collections::generic::ilist< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition list.hpp:97
virtual reference back()
Returns a reference to the last element in the container.
Definition list.hpp:196
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:40
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp: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.hpp:19
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition invalid_operation_exception.hpp:19
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:35
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
std::type_info type
Stores information about a type.
Definition type.hpp:23
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.
@ 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.hpp:10