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 "params.h"
8#include "../object_model/read_only_collection.h"
9#include "../../argument_exception.h"
10#include "../../argument_out_of_range_exception.h"
11#include "../../index_out_of_range_exception.h"
12#include "../../box_integer.h"
13#include "../../invalid_operation_exception.h"
14#include "../../intptr.h"
15#include "../../is.h"
16#include "../../literals.h"
17#include "../../object.h"
18#include "../../new_ptr.h"
19#include "../../ptr.h"
20#include "../../string.h"
21#include <utility>
22#include <vector>
23
25namespace xtd {
27 namespace collections {
29 namespace generic {
71 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
72 class list : public xtd::object, public xtd::collections::generic::ilist<type_t>, public xtd::iequatable<xtd::collections::generic::list<type_t, allocator_t>> {
73 public:
75
78 using value_type = type_t;
82 using base_type = typename std::vector<typename std::conditional<std::is_same<bool, value_type>::value, xtd::byte, value_type>::type, allocator_type>;
94 using const_pointer = const value_type*;
100 using reverse_iterator = typename base_type::reverse_iterator;
102 using const_reverse_iterator = typename base_type::const_reverse_iterator;
106
108
113
115
126 list() noexcept = default;
127
130 explicit list(const allocator_type& alloc) noexcept : data_(xtd::new_ptr<struct data>(alloc)) {}
135 list(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(count, value, alloc)) {}
139 explicit list(size_type count, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(count, alloc)) {}
144 template<typename input_iterator_t>
145 list(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(first, last, alloc)) {}
154 list(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(collection, alloc)) {}
155
158 list(const list& list) : data_(xtd::new_ptr<struct data>(list)) {}
161 list(const base_type& list) : data_(xtd::new_ptr<struct data>(list)) {}
165 list(const list& list, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(list, alloc)) {}
169 list(const base_type& list, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(list, alloc)) {}
173 list(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<struct data>(items, alloc)) {}
174
177 list(list&& other) : data_(xtd::new_ptr<struct data>(std::move(other))) {other.data_ = xtd::new_ptr<struct data>();}
180 list(base_type&& other) : data_(xtd::new_ptr<struct data>(std::move(other))) {other.clear();}
184 list(list&& other, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(std::move(other)), alloc) {other.data_ = xtd::new_ptr<struct data>();}
188 list(base_type&& other, const allocator_type& alloc) : data_(xtd::new_ptr<struct data>(std::move(other), alloc)) {other.items.clear();}
190
192
197 virtual reference back() {return at(count() - 1);}
201 virtual const_reference back() const {return at(count() - 1);}
202
205 const_iterator begin() const noexcept override {return ienumerable<value_type>::begin();}
208 iterator begin() noexcept override {return ienumerable<value_type>::begin();}
209
232 virtual size_type capacity() const noexcept {return data_->items.capacity();}
255 virtual void capacity(size_type value) {
256 if (value < count()) throw argument_out_of_range_exception {csf_};
257 reserve(value);
258 }
259
262 const_iterator cbegin() const noexcept override {return ienumerable<value_type>::cbegin();}
263
266 const_iterator cend() const noexcept override {return ienumerable<value_type>::cend();}
267
289 size_type count() const noexcept override {return size();}
290
294 virtual const_reverse_iterator crbegin() const noexcept {return data_->items.crbegin();}
295
299 virtual const_reverse_iterator crend() const noexcept {return data_->items.crend();}
300
304 virtual pointer data() noexcept {return reinterpret_cast<pointer>(data_->items.data());}
308 virtual const_pointer data() const noexcept {return reinterpret_cast<const_pointer>(data_->items.data());}
309
312 virtual bool empty() const noexcept {return data_->items.empty();}
313
316 const_iterator end() const noexcept override {return ienumerable<value_type>::end();}
319 iterator end() noexcept override {return ienumerable<value_type>::end();}
320
324 virtual reference front() {return at(0);}
328 virtual const_reference front() const {return at(0);}
329
330 bool is_fixed_size() const noexcept override {return false;}
331 bool is_read_only() const noexcept override {return false;}
332 bool is_synchronized() const noexcept override {return false;}
333
336 virtual const base_type& items() const noexcept {return data_->items;}
339 virtual base_type& items() noexcept {return data_->items;}
340
343 virtual size_type max_size() const noexcept {return data_->items.max_size();}
344
348 virtual reverse_iterator rbegin() noexcept {return data_->items.rbegin();}
352 virtual const_reverse_iterator rbegin() const noexcept {return data_->items.rbegin();}
353
357 virtual reverse_iterator rend() noexcept {return data_->items.rend();}
361 virtual const_reverse_iterator rend() const noexcept {return data_->items.rend();}
362
365 virtual size_type size() const noexcept {return data_->items.size();}
366
367 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
369
371
386 void add(const type_t& item) override {push_back(item);}
387
397
406 void add_range(std::initializer_list<type_t> il) {insert_range(count(), il);}
407
409 template<typename enumerable_t>
410 void add_range(const enumerable_t& enumerable) {insert_range(count(), enumerable);}
412
416 void assign(size_type count, const type_t& value) {
417 ++data_->version;
418 data_->items.assign(count, value);
419 }
420
425 template<typename input_iterator_t>
426 void assign(input_iterator_t first, input_iterator_t last) {
427 ++data_->version;
428 data_->items.assign(first, last);
429 }
430
435 read_only_collection as_read_only() const noexcept {return read_only_collection {new_ptr<list<value_type>>(*this)};}
436
439 virtual void assign(std::initializer_list<type_t> items) {
440 clear();
441 for (auto item : items)
442 push_back(item);
443 }
444
449 virtual reference at(size_type index) {
450 if (index >= count()) throw index_out_of_range_exception {csf_};
451 return reinterpret_cast<reference>(data_->items.at(index));
452 }
457 virtual const_reference at(size_type index) const {
458 if (index >= count()) throw index_out_of_range_exception {csf_};
459 return reinterpret_cast<const_reference>(data_->items.at(index));
460 }
461
462 void clear() override {
463 ++data_->version;
464 data_->items.clear();
465 }
466
467 bool contains(const type_t& value) const noexcept override {
468 for (const type_t& item : data_->items)
469 if (item == value) return true;
470 return false;
471 }
472
483 virtual void copy_to(xtd::array<type_t>& array) const {copy_to(0, array, 0, count());}
484
485 void copy_to(xtd::array<type_t>& array, size_type array_index) const override {copy_to(0, array, array_index, count());}
486
501 virtual void copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const {
502 if (index + count > this->count() || array_index + count > array.size()) throw xtd::argument_exception {csf_};
503 auto i = size_type {0}, c = size_type {0};
504 for (const type_t& item : *this) {
505 if (i >= index + count) return;
506 if (i >= index) {
507 array[array_index + c] = item;
508 c += 1;
509 }
510 i += 1;
511 }
512 }
513
520 template<typename... args_t>
521 iterator emplace(const_iterator pos, args_t&&... args) {
522 ++data_->version;
523 return data_->items.eplace(std::forward<args_t>(args)...);
524 }
525
530 template<typename... args_t>
531 reference emplace_back(args_t&&... args) {
532 ++data_->version;
533 return data_->items.emplace_back(std::forward<args_t>(args)...);
534 }
535
536 bool equals(const object& obj) const noexcept override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>&>(obj));}
537 bool equals(const list& rhs) const noexcept override {return data_->items == rhs.data_->items && data_->version == rhs.data_->version;}
538
547 ++data_->version;
548 return to_iterator(data_->items.erase(to_base_type_iterator(pos)));
549 }
559 ++data_->version;
560 return to_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
561 }
562
565 virtual allocator_type get_allocator() const {return data_->items.get_allocator();}
566
570 virtual base_type& get_base_type() noexcept {return data_->items;}
573 virtual const base_type& get_base_type() const noexcept {return data_->items;}
574
575 enumerator<value_type> get_enumerator() const noexcept override {
576 class list_enumerator : public ienumerator<value_type> {
577 public:
578 explicit list_enumerator(const list& items, size_type version) : items_(items), version_(version) {}
579
580 const value_type& current() const override {
581 if (version_ != items_.data_->version) throw xtd::invalid_operation_exception {"Collection was modified; enumeration operation may not execute.", csf_};
582 return items_.at(index_);
583 }
584
585 bool move_next() override {
586 if (version_ != items_.data_->version) throw xtd::invalid_operation_exception {"Collection was modified; enumeration operation may not execute.", csf_};
587 return ++index_ < items_.count();
588 }
589
590 void reset() override {
591 version_ = items_.data_->version;
592 index_ = list::npos;
593 }
594
595 protected:
596 const list& items_;
597 size_type index_ = list::npos;
598 size_type version_ = 0;
599 };
600 return {new_ptr<list_enumerator>(*this, data_->version)};
601 }
602
616 if (index + count > this->count()) throw xtd::argument_exception {csf_};
617
618 return list<type_t> {begin() + index, begin() + index + count};
619 }
620
624 size_type index_of(const type_t& value) const noexcept override {
625 if (count() == 0) return npos;
626 return index_of(value, 0, count());
627 }
628
634 virtual size_type index_of(const type_t& value, size_type index) const {return index_of(value, index, count() - index);}
635
642 virtual size_type index_of(const type_t& value, size_type index, size_type count) const {
643 if (index >= this->count()) throw xtd::argument_out_of_range_exception {csf_};
644 if (index + count > this->count()) throw xtd::argument_out_of_range_exception {csf_};
645
646 for (auto i = index; i < index + count; ++i)
647 if (at(i) == value) return i;
648 return npos;
649 }
650
657 virtual iterator insert(const_iterator pos, const type_t& value) {
658 ++data_->version;
659 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
660 }
667 virtual iterator insert(const_iterator pos, const type_t&& value) {
668 ++data_->version;
669 return to_iterator(data_->items.insert(to_base_type_iterator(pos), value));
670 }
678 virtual iterator insert(const_iterator pos, size_type count, const type_t& value) {
679 ++data_->version;
680 return to_iterator(data_->items.insert(to_base_type_iterator(pos), count, value));
681 }
689 template<typename input_iterator_t>
690 iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last) {
691 ++data_->version;
692 return to_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
693 }
700 virtual iterator insert(const_iterator pos, const std::initializer_list<type_t>& items) {
701 ++data_->version;
702 return to_iterator(data_->items.insert(to_base_type_iterator(pos), items.begin(), items.end()));
703 }
704
710 void insert(size_type index, const type_t& value) override {
711 if (index > count()) throw xtd::argument_out_of_range_exception {csf_};
712 insert(begin() + index, value);
713 }
714
725 if (index > count()) throw xtd::argument_out_of_range_exception {csf_};
726
727 // If the collection is this instance, it must be copied to avoid an infinite loop.
728 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
729 auto items = list<type_t>(enumerable.begin(), enumerable.end());
730 insert(begin() + index, items.begin(), items.end());
731 return;
732 }
733
734 insert(begin() + index, enumerable.begin(), enumerable.end());
735 }
736
746 virtual void insert_range(size_type index, const std::initializer_list<type_t>& items) {
747 if (index > count()) throw xtd::argument_out_of_range_exception {csf_};
748 insert(begin() + index, items);
749 }
750
752 template<typename ienumerable_t>
753 void insert_range(size_type index, const ienumerable_t& enumerable) {
754 if (index > count()) throw xtd::argument_out_of_range_exception {csf_};
755
756 // If the collection is this instance, it must be copied to avoid an infinite loop.
757 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
758 auto items = list<type_t>(enumerable.begin(), enumerable.end());
759 insert(begin() + index, items.begin(), items.end());
760 return;
761 }
762
763 insert(begin() + index, enumerable.begin(), enumerable.end());
764 }
766
770 virtual void pop_back() {
771 ++data_->version;
772 data_->items.pop_back();
773 }
774
779 virtual void push_back(const type_t& value) {
780 ++data_->version;
781 data_->items.push_back(value);
782 }
787 virtual void push_back(type_t&& value) {
788 ++data_->version;
789 data_->items.push_back(value);
790 }
791
792 bool remove(const type_t& item) override {
793 if (count() == 0) return false;
794 for (auto index = size_type {0}; index < count(); ++index) {
795 if (at(index) != item) continue;
796 remove_at(index);
797 return true;
798 }
799 return false;
800 }
801
805 void remove_at(size_type index) override {
806 if (index >= count()) throw xtd::argument_out_of_range_exception {csf_};
807
808 if (index == count() - 1) pop_back();
809 else erase(begin() + index);
810 }
811
820 virtual void remove_range(size_type index, size_type count) {
821 if (index + count >= this->count()) throw xtd::argument_out_of_range_exception {csf_};
822
823 erase(begin() + index, begin() + index + count);
824 }
825
831 virtual void reserve(size_type new_cap) {data_->items.reserve(new_cap);}
832
843 virtual void resize(size_type count, const value_type& value) {
845 if (count == size()) return;
846 ++data_->version;
847 data_->items.resize(count, value);
848 }
849
853 virtual void shrink_to_fit() {data_->items.shrink_to_fit();}
854
857 virtual void swap(list& other) noexcept {
858 ++data_->version;
859 data_->items.swap(other.data_->items);
860 }
861
869 virtual xtd::array<value_type> to_array() const noexcept {return xtd::array<value_type>(begin(), end());}
870
871 string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
872
893 virtual void trim_excess() {shrink_to_fit();}
895
897
902 list& operator =(const list& other) = default;
906 list& operator =(list&& other) noexcept {
907 data_->version = std::move(other.data_->version);
908 data_->items = std::move(other.data_->items);
909 return *this;
910 }
914 list& operator =(std::initializer_list<type_t>& items) {
915 data_->version = 0;
916 data_->items = items;
917 return *this;
918 }
919
924 const_reference operator [](size_type index) const override {return at(index);}
929 reference operator [](size_type index) override {return at(index);}
930
933 virtual operator const base_type&() const noexcept {return data_->items;}
936 virtual operator base_type&() noexcept {return data_->items;}
938
939 private:
940 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
941 if (value == begin()) return data_->items.begin();
942 if (value == end()) return data_->items.end();
943 return data_->items.begin() + (value - begin());
944 }
945
946 iterator to_iterator(typename base_type::iterator value) noexcept {
947 if (value == data_->items.begin()) return begin();
948 if (value == data_->items.end()) return end();
949 return begin() + (value - data_->items.begin());
950 }
951
952 struct data {
953 data() = default;
954 explicit data(const allocator_type& alloc) noexcept : items(alloc) {}
955 data(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : items(count, value, alloc) {}
956 explicit data(size_type count, const allocator_type& alloc = allocator_type()) : items(count, alloc) {}
957 template<typename input_iterator_t>
958 data(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : items(first, last, alloc) {}
959 data(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : items(collection.begin(), collection.end(), alloc) {}
960 data(const list& list) : items(list.data_->items), version(list.data_->version) {}
961 data(const base_type& list) : items(list) {}
962 data(const list& list, const allocator_type& alloc) : items(list.data_->items, alloc), version(list.data_->version) {}
963 data(const base_type& list, const allocator_type& alloc) : items(list, alloc) {}
964 data(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : items(items.begin(), items.end(), alloc) {}
965 data(list&& other) : items(std::move(other.data_->items)), version(std::move(other.data_->version)) {other.data_->items.clear(); other.data_->version = 0;}
966 data(base_type&& other) : items(std::move(other)) {other.clear();}
967 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;}
968 data(base_type&& other, const allocator_type& alloc) : items(std::move(other), alloc) {}
969
970 data(const data&) = default;
971 data& operator =(const data&) = default;
972
973 base_type items;
974 size_type version = 0;
975 xtd::object sync_root;
976 };
977
978 xtd::ptr<struct data> data_ = xtd::new_ptr<struct data>();
979 };
980
982 // C++17 deduction
983 // {
984 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
985 list(std::initializer_list<type_t>) -> list<type_t, allocator_t>;
986
987 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
988 list(const xtd::collections::generic::ienumerable<type_t>&) -> list<type_t, allocator_t>;
989
990 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
991 list(const xtd::collections::generic::ilist<type_t>&) -> list<type_t, allocator_t>;
992
993 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
994 list(const std::vector<type_t>&) -> list<type_t, allocator_t>;
995
996 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
997 list(const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
998
999 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
1000 list(std::vector<type_t>&&) -> list<type_t, allocator_t>;
1001
1002 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<typename std::conditional<std::is_same<bool, type_t>::value, char, type_t>::type>>
1003 list(list<type_t, allocator_t>&&) -> list<type_t, allocator_t>;
1004 // }
1006 }
1007 }
1008}
Contains xtd::collections::generic::helpers::allocator alias.
The exception that is thrown when one of the arguments provided to a method is not valid.
Definition argument_exception.h:23
The exception that is thrown when one of the arguments provided to a method is out of range.
Definition argument_out_of_range_exception.h:22
static basic_string join(const basic_string separator, const collection_t &values) noexcept
Concatenates a specified separator basic_string between each element of a specified object array,...
Definition basic_string.h:2178
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:209
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:205
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.h:213
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.h:198
Supports a simple iteration over a generic collection.
Definition enumerator.h:31
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.h:35
Supports a simple iteration over a generic collection.
Definition ienumerator.h:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.h:41
typename icollection< type_t >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:47
typename icollection< type_t >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ilist.h:49
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:72
void insert(size_type index, const type_t &value) override
Inserts an element into the xtd::collections::generic::list <type_t> at the specified index.
Definition list.h:710
bool is_read_only() const noexcept override
Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
Definition list.h:331
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:304
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition list.h:336
virtual void swap(list &other) noexcept
Exchanges the contents and capacity of the container with those of other. Does not invoke any move,...
Definition list.h:857
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.h:386
virtual void push_back(type_t &&value)
Appends the given element value to the end of the container.
Definition list.h:787
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:449
list get_range(size_type index, size_type count)
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.h:615
list(base_type &&other)
Move constructor with specified base type list.
Definition list.h:180
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:205
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.h:457
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.h:536
virtual const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:299
virtual size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition list.h:343
virtual void copy_to(size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array,...
Definition list.h:501
virtual reference front()
Returns a reference to the first element in the container.
Definition list.h:324
const value_type * const_pointer
Represents the const pointer of list value type.
Definition list.h:94
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
Definition list.h:367
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.h:111
virtual void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.h:893
virtual xtd::array< value_type > to_array() const noexcept
Copies the elements of the xtd::collections::generic::list <type_t> to a new array.
Definition list.h:869
list(std::initializer_list< type_t > items, const allocator_type &alloc=allocator_type())
Constructs the container with the contents of the specified initializer list, and allocator.
Definition list.h:173
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:316
virtual void insert_range(size_type index, const xtd::collections::generic::ienumerable< type_t > &enumerable)
Inserts copy of elements from a collection into the xtd::collections::generic::list <type_t> at the s...
Definition list.h:724
void remove_at(size_type index) override
Removes the element at the specified index of the xtd::collections::generic::list <type_t>.
Definition list.h:805
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.h:416
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:357
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.h:924
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:262
virtual void pop_back()
Removes the last element of the container.
Definition list.h:770
void assign(input_iterator_t first, input_iterator_t last)
Replaces the contents with copies of those in the range [first, last).
Definition list.h:426
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of list value type.
Definition list.h:100
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.h:184
void copy_to(xtd::array< type_t > &array, size_type array_index) const override
Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array,...
Definition list.h:485
virtual void copy_to(xtd::array< type_t > &array) const
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array.
Definition list.h:483
list(input_iterator_t first, input_iterator_t last, const allocator_type &alloc=allocator_type())
Constructs the container with the contents of the range [first, last).
Definition list.h:145
typename std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Represents the list base type.
Definition list.h:82
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.h:308
void clear() override
Removes all items from the xtd::collections::generic::icollection <type_t>.
Definition list.h:462
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.h:339
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.h:312
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.h:871
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.h:328
virtual base_type & get_base_type() noexcept
Returns the underlying base type.
Definition list.h:570
size_type index_of(const type_t &value) const noexcept override
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:624
reference emplace_back(args_t &&... args)
Appends a new element to the end of the container. The element is constructed through std::allocator_...
Definition list.h:531
typename xtd::collections::generic::helpers::allocator< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type > allocator_type
Represents the list allocator type.
Definition list.h:80
bool is_synchronized() const noexcept override
Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is sync...
Definition list.h:332
list(const list &list)
Default copy constructor with specified list.
Definition list.h:158
xtd::ptrdiff difference_type
Represents the list difference type (usually xtd::ptrdiff).
Definition list.h:86
list(const xtd::collections::generic::ienumerable< type_t > &collection, const allocator_type &alloc=allocator_type())
Initializes a new instance of the xtd::collections::generic::list <type_t> class that contains elemen...
Definition list.h:154
list() noexcept=default
Initializes a new instance of the xtd::collections::generic::list class that is empty.
virtual const_reference back() const
Returns a reference to the last element in the container.
Definition list.h:201
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.h:169
virtual void shrink_to_fit()
Requests the removal of unused capacity.
Definition list.h:853
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.h:165
bool is_fixed_size() const noexcept override
Gets a value indicating whether the xtd::collections::generic::ilist <type_t> has a fixed size.
Definition list.h:330
xtd::size size_type
Represents the list size type (usually xtd::size).
Definition list.h:84
typename xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Represents the read only collection of of list.
Definition list.h:104
const value_type & const_reference
Represents the const reference of list value type.
Definition list.h:90
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:319
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.h:232
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.h:439
virtual const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:294
virtual allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition list.h:565
virtual void remove_range(size_type index, size_type count)
Removes a range of elements from the xtd::collections::generic::list <type_t>.
Definition list.h:820
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.h:289
virtual void reserve(size_type new_cap)
Increase the capacity of the vector (the total number of elements that the vector can hold without re...
Definition list.h:831
list(size_type count, const type_t &value, const allocator_type &alloc=allocator_type())
Constructs the container with specified count copies of elements with specified value.
Definition list.h:135
list(list &&other)
Move constructor with specified list.
Definition list.h:177
list & operator=(const list &other)=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
typename base_type::const_reverse_iterator const_reverse_iterator
Represents the const reverse iterator of list value type.
Definition list.h:102
virtual const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.h:361
value_type & reference
Represents the reference of list value type.
Definition list.h:88
virtual void insert_range(size_type index, const std::initializer_list< type_t > &items)
Inserts copy of elements from a collection into the xtd::collections::generic::list <type_t> at the s...
Definition list.h:746
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through a collection.
Definition list.h:575
void add_range(const xtd::collections::generic::ienumerable< type_t > &enumerable)
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.h:396
virtual void resize(size_type count, const value_type &value)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.h:843
read_only_collection as_read_only() const noexcept
Returns a read-only xtd::collections::object_model::read_only_collection <type_t> wrapper for the cur...
Definition list.h:435
virtual reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:348
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.h:208
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.h:255
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:365
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.h:657
virtual void resize(size_type count)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.h:837
virtual size_type index_of(const type_t &value, size_type index) const
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:634
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.h:161
virtual const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last el...
Definition list.h:352
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.h:188
void add_range(std::initializer_list< type_t > il)
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.h:406
value_type * pointer
Represents the pointer of list value type.
Definition list.h:92
virtual iterator erase(const_iterator first, const_iterator last)
Erases the specified elements from the container.
Definition list.h:558
virtual void push_back(const type_t &value)
Appends the given element value to the end of the container.
Definition list.h:779
virtual const base_type & get_base_type() const noexcept
Returns the underlying base type.
Definition list.h:573
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.h:266
virtual iterator insert(const_iterator pos, const std::initializer_list< type_t > &items)
Inserts elements at the specified location in the container.
Definition list.h:700
virtual iterator erase(const_iterator pos)
Erases the specified elements from the container.
Definition list.h:546
bool contains(const type_t &value) const noexcept override
Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
Definition list.h:467
type_t value_type
Represents the list value type.
Definition list.h:78
virtual size_type index_of(const type_t &value, size_type index, size_type count) const
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.h:642
iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last)
Inserts elements at the specified location in the container.
Definition list.h:690
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.h:521
bool remove(const type_t &item) override
Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <ty...
Definition list.h:792
list(size_type count, const allocator_type &alloc=allocator_type())
Constructs the container with specified count default-inserted instances of type_t....
Definition list.h:139
typename xtd::collections::generic::ilist< type_t >::iterator iterator
Represents the iterator of list value type.
Definition list.h:96
virtual iterator insert(const_iterator pos, size_type count, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.h:678
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.h:667
typename xtd::collections::generic::ilist< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition list.h:98
virtual reference back()
Returns a reference to the last element in the container.
Definition list.h:197
Provides the base class for a generic read-only collection.
Definition read_only_collection.h:40
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
The exception that is thrown when an attempt is made to access an element of an array with an index t...
Definition index_out_of_range_exception.h:18
The exception that is thrown when a method call is invalid for the object's current state.
Definition invalid_operation_exception.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
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
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
size_t size
Represents a size of any object in bytes.
Definition size.h:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.h:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.h:23
std::type_info type
Stores information about a type.
Definition type.h:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.h:23
@ other
The operating system is other.
@ 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
Contains xtd::collections::generic::params class.