xtd 0.2.0
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1
4#pragma once
5#include "helpers/allocator.h"
6#include "ilist.h"
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"
14#include "../../is.h"
15#include "../../literals.h"
16#include "../../object.h"
17#include "../../new_ptr.h"
18#include "../../ptr.h"
19#include "../../string.h"
20#include <utility>
21#include <vector>
22
24namespace xtd {
26 namespace collections {
28 namespace generic {
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>>
71 class list : public xtd::object, public xtd::collections::generic::ilist<type_t>, public xtd::iequatable<xtd::collections::generic::list<type_t, allocator_t>> {
72 public:
74
77 using value_type = type_t;
81 using base_type = typename std::vector<typename std::conditional<std::is_same<bool, value_type>::value, xtd::byte, value_type>::type, allocator_type>;
93 using const_pointer = const value_type*;
99 using reverse_iterator = typename base_type::reverse_iterator;
101 using const_reverse_iterator = typename base_type::const_reverse_iterator;
105
107
112
114
125 list() noexcept = default;
126
129 explicit list(const allocator_type& alloc) noexcept : data_(xtd::new_ptr<struct data>(alloc)) {}
134 list(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(count, value, alloc)) {}
138 explicit list(size_type count, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(count, alloc)) {}
143 template<typename input_iterator_t>
144 list(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(first, last, alloc)) {}
153 list(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(collection, alloc)) {}
154
157 list(const list& list) : data_(xtd::new_ptr<struct data>(list)) {}
160 list(const base_type& list) : data_(xtd::new_ptr<struct data>(list)) {}
164 list(const list& list, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(list, alloc)) {}
168 list(const base_type& list, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(list, alloc)) {}
172 list(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(items, alloc)) {}
173
176 list(list&& other) : data_(xtd::new_ptr<struct data>(std::move(other))) {other.data_ = xtd::new_ptr<struct data>();}
179 list(base_type&& other) : data_(xtd::new_ptr<struct data>(std::move(other))) {other.clear();}
183 list(list&& other, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(std::move(other)), alloc) {other.data_ = xtd::new_ptr<struct data>();}
187 list(base_type&& other, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(std::move(other), alloc)) {other.items.clear();}
189
191
196 virtual reference back() {return at(count() - 1);}
200 virtual const_reference back() const {return at(count() - 1);}
201
204 const_iterator begin() const noexcept override {return ienumerable<value_type>::begin();}
207 iterator begin() noexcept override {return ienumerable<value_type>::begin();}
208
231 virtual size_type capacity() const noexcept {return data_->items.capacity();}
254 virtual void capacity(size_type value) {
255 if (value < count()) throw argument_out_of_range_exception {};
256 reserve(value);
257 }
258
261 const_iterator cbegin() const noexcept override {return ienumerable<value_type>::cbegin();}
262
265 const_iterator cend() const noexcept override {return ienumerable<value_type>::cend();}
266
288 size_type count() const noexcept override {return size();}
289
293 virtual const_reverse_iterator crbegin() const noexcept {return data_->items.crbegin();}
294
298 virtual const_reverse_iterator crend() const noexcept {return data_->items.crend();}
299
303 virtual pointer data() noexcept {return reinterpret_cast<pointer>(data_->items.data());}
307 virtual const_pointer data() const noexcept {return reinterpret_cast<const_pointer>(data_->items.data());}
308
311 virtual bool empty() const noexcept {return data_->items.empty();}
312
315 const_iterator end() const noexcept override {return ienumerable<value_type>::end();}
318 iterator end() noexcept override {return ienumerable<value_type>::end();}
319
323 virtual reference front() {return at(0);}
327 virtual const_reference front() const {return at(0);}
328
329 bool is_fixed_size() const noexcept override {return false;}
330 bool is_read_only() const noexcept override {return false;}
331 bool is_synchronized() const noexcept override {return false;}
332
335 virtual const base_type& items() const noexcept {return data_->items;}
338 virtual base_type& items() noexcept {return data_->items;}
339
342 virtual size_type max_size() const noexcept {return data_->items.max_size();}
343
347 virtual reverse_iterator rbegin() noexcept {return data_->items.rbegin();}
351 virtual const_reverse_iterator rbegin() const noexcept {return data_->items.rbegin();}
352
356 virtual reverse_iterator rend() noexcept {return data_->items.rend();}
360 virtual const_reverse_iterator rend() const noexcept {return data_->items.rend();}
361
364 virtual size_type size() const noexcept {return data_->items.size();}
365
366 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
368
370
385 void add(const type_t& item) override {push_back(item);}
386
396
405 void add_range(std::initializer_list<type_t> il) {insert_range(count(), il);}
406
408 template<typename enumerable_t>
409 void add_range(const enumerable_t& enumerable) {insert_range(count(), enumerable);}
411
415 void assign(size_type count, const type_t& value) {
416 ++data_->version;
417 data_->items.assign(count, value);
418 }
419
424 template<typename input_iterator_t>
425 void assign(input_iterator_t first, input_iterator_t last) {
426 ++data_->version;
427 data_->items.assign(first, last);
428 }
429
434 read_only_collection as_read_only() const noexcept {return read_only_collection {new_ptr<list<value_type>>(*this)};}
435
438 virtual void assign(std::initializer_list<type_t> items) {
439 clear();
440 for (auto item : items)
441 push_back(item);
442 }
443
448 virtual reference at(size_type index) {
449 if (index >= count()) throw index_out_of_range_exception {};
450 return reinterpret_cast<reference>(data_->items.at(index));
451 }
456 virtual const_reference at(size_type index) const {
457 if (index >= count()) throw index_out_of_range_exception {};
458 return reinterpret_cast<const_reference>(data_->items.at(index));
459 }
460
461 void clear() override {
462 ++data_->version;
463 data_->items.clear();
464 }
465
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;
469 return false;
470 }
471
482 virtual void copy_to(xtd::array<type_t>& array) const {copy_to(0, array, 0, count());}
483
484 void copy_to(xtd::array<type_t>& array, size_type array_index) const override {copy_to(0, array, array_index, count());}
485
500 virtual void copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const {
501 if (index + count > this->count() || array_index + count > array.size()) throw xtd::argument_exception {};
502 auto i = size_type {0}, c = size_type {0};
503 for (const type_t& item : *this) {
504 if (i >= index + count) return;
505 if (i >= index) {
506 array[array_index + c] = item;
507 c += 1;
508 }
509 i += 1;
510 }
511 }
512
519 template<typename... args_t>
520 iterator emplace(const_iterator pos, args_t&&... args) {
521 ++data_->version;
522 return data_->items.eplace(std::forward<args_t>(args)...);
523 }
524
529 template<typename... args_t>
530 reference emplace_back(args_t&&... args) {
531 ++data_->version;
532 return data_->items.emplace_back(std::forward<args_t>(args)...);
533 }
534
535 bool equals(const object& obj) const noexcept override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>&>(obj));}
536 bool equals(const list& rhs) const noexcept override {return data_->items == rhs.data_->items && data_->version == rhs.data_->version;}
537
546 ++data_->version;
547 return to_iterator(data_->items.erase(to_base_type_iterator(pos)));
548 }
558 ++data_->version;
559 return to_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
560 }
561
564 virtual allocator_type get_allocator() const {return data_->items.get_allocator();}
565
569 virtual base_type& get_base_type() noexcept {return data_->items;}
572 virtual const base_type& get_base_type() const noexcept {return data_->items;}
573
574 enumerator<value_type> get_enumerator() const noexcept override {
575 class list_enumerator : public ienumerator<value_type> {
576 public:
577 explicit list_enumerator(const list& items, size_type version) : items_(items), version_(version) {}
578
579 const value_type& current() const override {
580 if (version_ != items_.data_->version) throw xtd::invalid_operation_exception {"Collection was modified; enumeration operation may not execute."};
581 return items_.at(index_);
582 }
583
584 bool move_next() override {
585 if (version_ != items_.data_->version) throw xtd::invalid_operation_exception {"Collection was modified; enumeration operation may not execute."};
586 return ++index_ < items_.count();
587 }
588
589 void reset() override {
590 version_ = items_.data_->version;
591 index_ = list::npos;
592 }
593
594 protected:
595 const list& items_;
596 size_type index_ = list::npos;
597 size_type version_ = 0;
598 };
599 return {new_ptr<list_enumerator>(*this, data_->version)};
600 }
601
615 if (index + count > this->count()) throw xtd::argument_exception {};
616
617 return list<type_t> {begin() + index, begin() + index + count};
618 }
619
623 size_type index_of(const type_t& value) const noexcept override {
624 if (count() == 0) return npos;
625 return index_of(value, 0, count());
626 }
627
633 virtual size_type index_of(const type_t& value, size_type index) const {return index_of(value, index, count() - index);}
634
641 virtual size_type index_of(const type_t& value, size_type index, size_type count) const {
642 if (index >= this->count()) throw xtd::argument_out_of_range_exception {};
643 if (index + count > this->count()) throw xtd::argument_out_of_range_exception {};
644
645 for (auto i = index; i < index + count; ++i)
646 if (at(i) == value) return i;
647 return npos;
648 }
649
656 virtual iterator insert(const_iterator pos, const type_t& value) {
657 ++data_->version;
658 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
659 }
666 virtual iterator insert(const_iterator pos, const type_t&& value) {
667 ++data_->version;
668 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
669 }
677 virtual iterator insert(const_iterator pos, size_type count, const type_t& value) {
678 ++data_->version;
679 return to_iterator(data_->items.insert(to_base_type_iterator(pos), count, value));
680 }
688 template<typename input_iterator_t>
689 iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last) {
690 ++data_->version;
691 return to_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
692 }
699 virtual iterator insert(const_iterator pos, const std::initializer_list<type_t>& items) {
700 ++data_->version;
701 return to_iterator(data_->items.insert(to_base_type_iterator(pos), items.begin(), items.end()));
702 }
703
709 void insert(size_type index, const type_t& value) override {
710 if (index > count()) throw xtd::argument_out_of_range_exception {};
711 insert(begin() + index, value);
712 }
713
724 if (index > count()) throw xtd::argument_out_of_range_exception {};
725
726 // If the collection is this instance, it must be copied to avoid an infinite loop.
727 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
728 auto items = list<type_t>(enumerable.begin(), enumerable.end());
729 insert(begin() + index, items.begin(), items.end());
730 return;
731 }
732
733 insert(begin() + index, enumerable.begin(), enumerable.end());
734 }
735
745 virtual void insert_range(size_type index, const std::initializer_list<type_t>& items) {
746 if (index > count()) throw xtd::argument_out_of_range_exception {};
747 insert(begin() + index, items);
748 }
749
751 template<typename ienumerable_t>
752 void insert_range(size_type index, const ienumerable_t& enumerable) {
753 if (index > count()) throw xtd::argument_out_of_range_exception {};
754
755 // If the collection is this instance, it must be copied to avoid an infinite loop.
756 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
757 auto items = list<type_t>(enumerable.begin(), enumerable.end());
758 insert(begin() + index, items.begin(), items.end());
759 return;
760 }
761
762 insert(begin() + index, enumerable.begin(), enumerable.end());
763 }
765
769 virtual void pop_back() {
770 ++data_->version;
771 data_->items.pop_back();
772 }
773
778 virtual void push_back(const type_t& value) {
779 ++data_->version;
780 data_->items.push_back(value);
781 }
786 virtual void push_back(type_t&& value) {
787 ++data_->version;
788 data_->items.push_back(value);
789 }
790
791 bool remove(const type_t& item) override {
792 if (count() == 0) return false;
793 for (auto index = size_type {0}; index < count(); ++index) {
794 if (at(index) != item) continue;
795 remove_at(index);
796 return true;
797 }
798 return false;
799 }
800
804 void remove_at(size_type index) override {
805 if (index >= count()) throw xtd::argument_out_of_range_exception {};
806
807 if (index == count() - 1) pop_back();
808 else erase(begin() + index);
809 }
810
819 virtual void remove_range(size_type index, size_type count) {
820 if (index + count >= this->count()) throw xtd::argument_out_of_range_exception {};
821
822 erase(begin() + index, begin() + index + count);
823 }
824
830 virtual void reserve(size_type new_cap) {data_->items.reserve(new_cap);}
831
842 virtual void resize(size_type count, const value_type& value) {
844 if (count == size()) return;
845 ++data_->version;
846 data_->items.resize(count, value);
847 }
848
852 virtual void shrink_to_fit() {data_->items.shrink_to_fit();}
853
856 virtual void swap(list& other) noexcept {
857 ++data_->version;
858 data_->items.swap(other.data_->items);
859 }
860
868 virtual xtd::array<value_type> to_array() const noexcept {return xtd::array<value_type>(begin(), end());}
869
870 string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
871
892 virtual void trim_excess() {shrink_to_fit();}
894
896
901 list& operator =(const list& other) = default;
905 list& operator =(list&& other) noexcept {
906 data_->version = std::move(other.data_->version);
907 data_->items = std::move(other.data_->items);
908 return *this;
909 }
913 list& operator =(std::initializer_list<type_t>& items) {
914 data_->version = 0;
915 data_->items = items;
916 return *this;
917 }
918
923 const_reference operator [](size_type index) const override {return at(index);}
928 reference operator [](size_type index) override {return at(index);}
929
932 operator const base_type&() const noexcept {return data_->items;}
935 operator base_type&() noexcept {return data_->items;}
937
938 private:
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());
943 }
944
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());
949 }
950
951 struct data {
952 data() = default;
953 explicit data(const allocator_type& alloc) noexcept : items(alloc) {}
954 data(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : items(count, value, alloc) {}
955 explicit data(size_type count, const allocator_type& alloc = allocator_type()) : items(count, alloc) {}
956 template<typename input_iterator_t>
957 data(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : items(first, last, alloc) {}
958 data(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : items(collection.begin(), collection.end(), alloc) {}
959 data(const list& list) : items(list.data_->items), version(list.data_->version) {}
960 data(const base_type& list) : items(list) {}
961 data(const list& list, const allocator_type& alloc) : items(list.data_->items, alloc), version(list.data_->version) {}
962 data(const base_type& list, const allocator_type& alloc) : items(list, alloc) {}
963 data(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : items(items.begin(), items.end(), alloc) {}
964 data(list&& other) : items(std::move(other.data_->items)), version(std::move(other.data_->version)) {other.data_->items.clear(); other.data_->version = 0;}
965 data(base_type&& other) : items(std::move(other)) {other.clear();}
966 data(list&& other, const allocator_type& alloc) : items(other.data_->items, alloc), version{std::move(other.data_->version)} {other.data_->items.clear(); other.data_->version = 0;}
967 data(base_type&& other, const allocator_type& alloc) : items(std::move(other), alloc) {}
968
969 data(const data&) = default;
970 data& operator =(const data&) = default;
971
972 base_type items;
973 size_type version = 0;
974 xtd::object sync_root;
975 };
976
977 xtd::ptr<struct data> data_ = xtd::new_ptr<struct data>();
978 };
979
981 // C++17 deduction
982 // {
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>;
985
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>>
987 list(const xtd::collections::generic::ienumerable<type_t>&) -> list<type_t, allocator_t>;
988
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>>
990 list(const xtd::collections::generic::ilist<type_t>&) -> list<type_t, allocator_t>;
991
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>;
994
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>;
997
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>;
1000
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>;
1003 // }
1005 }
1006 }
1007}
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
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 a method call is invalid for the object's current state.
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
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
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.
@ c
The C key.
@ i
The I key.
@ 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