xtd 0.2.0
list.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "helpers/equator.hpp"
7#include "comparer.hpp"
8#include "ilist.hpp"
9#define __XTD_CORE_INTERNAL__
11#undef __XTD_CORE_INTERNAL__
13#include "../../action.hpp"
16#include "../../box_integer.hpp"
17#include "../../comparison.hpp"
18#include "../../converter.hpp"
21#include "../../intptr.hpp"
22#include "../../is.hpp"
23#include "../../object.hpp"
24#include "../../new_ptr.hpp"
25#include "../../predicate.hpp"
26#include "../../ptr.hpp"
27#include "../../string.hpp"
28#include <utility>
29#include <vector>
30
32namespace xtd {
34 namespace collections {
36 namespace generic {
78 template<class type_t, class allocator_t>
79 class list : public xtd::object, public xtd::collections::generic::ilist<type_t>, public xtd::iequatable<xtd::collections::generic::list<type_t, allocator_t >> {
80 struct __comparer__ {
81 __comparer__(const xtd::collections::generic::icomparer<type_t>& comparer) : comparer_(comparer) {}
82 bool operator()(const type_t& e1, const type_t& e2) const {return comparer_.compare(e1, e2) < 0;}
84 };
85
86 struct __comparison_comparer__ {
87 __comparison_comparer__(xtd::comparison<const type_t&> comparison) : comparison_(comparison) {}
88 bool operator()(const type_t& e1, const type_t& e2) const {return comparison_(e1, e2) < 0;}
90 };
91
92 struct __enumerator__ : public ienumerator<type_t> {
93 public:
94 explicit __enumerator__(const list& items, xtd::size version) : items_(items), version_(version) {}
95
96 const type_t& current() const override {
97 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
98 if (index_ < items_.count()) return items_[index_];
99 static thread_local auto default_value = value_type {};
100 return default_value;
101 }
102
103 bool move_next() override {
104 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
105 return ++index_ < items_.count();
106 }
107
108 void reset() override {
109 version_ = items_.data_->version;
110 index_ = list::npos;
111 }
112
113 protected:
114 const list& items_;
115 xtd::size index_ = list::npos;
116 xtd::size version_ = 0;
117 };
118
119 public:
121
124 using value_type = type_t;
128 using base_type = std::vector<typename std::conditional<std::is_same<bool, value_type>::value, xtd::byte, value_type>::type, allocator_type>;
142 using const_pointer = const value_type*;
148 using reverse_iterator = typename base_type::reverse_iterator;
150 using const_reverse_iterator = typename base_type::const_reverse_iterator;
154
156
159 inline static constexpr size_type npos = xtd::collections::generic::ilist<type_t>::npos;
161
163
174 list() noexcept = default;
175
178 explicit list(const allocator_type& alloc) noexcept : data_(xtd::new_ptr<list_data>(alloc)) {}
183 list(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(count, value, alloc)) {}
187 explicit list(size_type count, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(count, alloc)) {}
192 template<class input_iterator_t>
193 list(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(first, last, alloc)) {}
202 list(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(collection, alloc)) {}
203
206 list(const list& list) : data_(xtd::new_ptr<list_data>(list)) {}
209 list(const base_type& list) : data_(xtd::new_ptr<list_data>(list)) {}
213 list(const list& list, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(list, alloc)) {}
217 list(const base_type& list, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(list, alloc)) {}
221 list(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(items, alloc)) {}
222
225 list(list&& other) : data_(xtd::new_ptr<list_data>(std::move(other))) {other.data_ = xtd::new_ptr<list_data>();}
228 list(base_type&& other) : data_(xtd::new_ptr<list_data>(std::move(other))) {other.clear();}
232 list(list&& other, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(std::move(other)), alloc) {other.data_ = xtd::new_ptr<list_data>();}
236 list(base_type&& other, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(std::move(other), alloc)) {other.items.clear();}
238
240
245 virtual reference back() {return at(count() - 1);}
249 virtual const_reference back() const {return at(count() - 1);}
250
253 const_iterator begin() const noexcept override {return ienumerable<value_type>::begin();}
256 iterator begin() noexcept override {return ienumerable<value_type>::begin();}
257
280 virtual size_type capacity() const noexcept {return data_->items.capacity();}
303 virtual void capacity(size_type value) {
305 if (value == capacity()) return;
306 if (value < capacity()) shrink_to_fit();
307 reserve(value);
308 }
309
312 const_iterator cbegin() const noexcept override {return ienumerable<value_type>::cbegin();}
313
316 const_iterator cend() const noexcept override {return ienumerable<value_type>::cend();}
317
339 size_type count() const noexcept override {return size();}
340
344 virtual const_reverse_iterator crbegin() const noexcept {return data_->items.crbegin();}
345
349 virtual const_reverse_iterator crend() const noexcept {return data_->items.crend();}
350
354 virtual pointer data() noexcept {return reinterpret_cast<pointer>(data_->items.data());}
358 virtual const_pointer data() const noexcept {return reinterpret_cast<const_pointer>(data_->items.data());}
359
362 virtual bool empty() const noexcept {return data_->items.empty();}
363
366 const_iterator end() const noexcept override {return ienumerable<value_type>::end();}
369 iterator end() noexcept override {return ienumerable<value_type>::end();}
370
374 virtual reference front() {return at(0);}
378 virtual const_reference front() const {return at(0);}
379
383 bool is_fixed_size() const noexcept override {return false;}
384
388 bool is_read_only() const noexcept override {return false;}
389
404 bool is_synchronized() const noexcept override {return false;}
405
408 virtual const_base_type& items() const noexcept {return data_->items;}
411 virtual base_type& items() noexcept {return data_->items;}
412
415 virtual size_type max_size() const noexcept {return data_->items.max_size();}
416
420 virtual reverse_iterator rbegin() noexcept {return data_->items.rbegin();}
424 virtual const_reverse_iterator rbegin() const noexcept {return data_->items.rbegin();}
425
429 virtual reverse_iterator rend() noexcept {return data_->items.rend();}
433 virtual const_reverse_iterator rend() const noexcept {return data_->items.rend();}
434
437 virtual size_type size() const noexcept {return data_->items.size();}
438
460 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
462
464
479 void add(const type_t& item) override {push_back(item);}
493 void add(type_t&& item) {push_back(std::move(item));}
494
504
513 void add_range(std::initializer_list<type_t> il) {insert_range(count(), il);}
514
516 template<class enumerable_t>
517 void add_range(const enumerable_t& enumerable) {insert_range(count(), enumerable);}
519
524 read_only_collection as_read_only() const noexcept {return read_only_collection {*this};}
525
529 void assign(size_type count, const type_t& value) {
530 ++data_->version;
531 data_->items.assign(count, value);
532 }
533
538 template<class input_iterator_t>
539 void assign(input_iterator_t first, input_iterator_t last) {
540 ++data_->version;
541 data_->items.assign(first, last);
542 }
543
546 virtual void assign(std::initializer_list<type_t> items) {
547 ++data_->version;
548 data_->items.assign(items.begin(), items.end());
549 }
550
555 virtual reference at(size_type index) {
557 return reinterpret_cast<reference>(data_->items.at(index));
558 }
559
563 virtual const_reference at(size_type index) const {
565 return reinterpret_cast<const_reference>(data_->items.at(index));
566 }
567
582
595
612 auto first = data_->items.begin();
613 auto last = data_->items.begin();
614 std::advance(first, index);
615 std::advance(last, index + count);
616 auto position = std::lower_bound(first, last, item, __comparer__{comparer});
617
618 if (position != data_->items.end() && !comparer.compare(item, *position))
619 return std::distance(data_->items.begin(), position);
620 return ~std::distance(data_->items.begin(), position);
621 }
622
627 void clear() override {
628 ++data_->version;
629 data_->items.clear();
630 }
631
635 bool contains(const type_t& value) const noexcept override {
636 for (const auto& item : data_->items)
637 if (helpers::equator<type_t> {}(reinterpret_cast<const type_t&>(item), value)) return true;
638 return false;
639 }
640
648 template<class output_t>
650 auto result = list<output_t> {};
651 for (const auto& item : *this)
652 result.add(converter(item));
653 return result;
654 }
655
666 virtual void copy_to(xtd::array<type_t>& array) const {copy_to(0, array, 0, count());}
674 void copy_to(xtd::array<type_t>& array, size_type array_index) const override {copy_to(0, array, array_index, count());}
689 virtual void copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const {
691 auto i = size_type {0}, c = size_type {0};
692 for (const type_t& item : *this) {
693 if (i >= index + count) return;
694 if (i >= index) {
695 array[array_index + c] = item;
696 c += 1;
697 }
698 i += 1;
699 }
700 }
701
708 template<class ...args_t>
709 iterator emplace(const_iterator pos, args_t&&... args) {
710 ++data_->version;
711 return to_type_iterator(data_->items.emplace(to_const_base_type_iterator(pos), std::forward<args_t>(args)...));
712 }
713
718 template<class ...args_t>
719 reference emplace_back(args_t&&... args) {
720 ++data_->version;
721 return data_->items.emplace_back(std::forward<args_t>(args)...);
722 }
723
728 data_->items.reserve(capacity);
729 return this->capacity();
730 }
731
732 bool equals(const object& obj) const noexcept override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>& > (obj));}
733 bool equals(const list& rhs) const noexcept override {
734 if (count() != rhs.count()) return false;
735 for (size_type i = 0; i < count(); i++)
736 if (!helpers::equator<type_t> {}(at(i), rhs.at(i))) return false;
737 return data_->version == rhs.data_->version;
738 }
739
747 virtual iterator erase(const_iterator pos) {
748 ++data_->version;
749 return to_type_iterator(data_->items.erase(to_const_base_type_iterator(pos)));
750 }
760 ++data_->version;
761 return to_type_iterator(data_->items.erase(to_const_base_type_iterator(first), to_const_base_type_iterator(last)));
762 }
763
775 bool exists(xtd::predicate<const type_t&> match) const {
776 for (const auto& item : *this)
777 if (match(item)) return true;
778 return false;
779 }
780
792 type_t find(xtd::predicate<const type_t&> match) const {
793 for (const auto& item : *this)
794 if (match(item)) return item;
795 return type_t {};
796 }
797
809 list<type_t> find_all(xtd::predicate<const type_t&> match) const {
810 auto result = list<type_t> {};
811 for (const auto& item : *this)
812 if (match(item)) result.add(item);
813 return result;
814 }
815
821 xtd::size find_index(xtd::predicate<const type_t&> match) const {return find_index(0, size(), match);}
829 xtd::size find_index(xtd::size start_index, xtd::predicate<const type_t&> match) const {return find_index(start_index, size() - start_index, match);}
838 xtd::size find_index(xtd::size start_index, xtd::size count, xtd::predicate<const type_t&> match) const {
840 for (auto index = start_index; index < start_index + count; ++index)
841 if (match((*this)[index])) return index;
842 return npos;
843 }
844
856 type_t find_last(xtd::predicate<const type_t&> match) const {
857 for (auto iterator = rbegin(); iterator != rend(); ++iterator)
858 if (match(*iterator)) return *iterator;
859 return type_t {};
860 }
861
867 xtd::size find_last_index(xtd::predicate<const type_t&> match) const {return find_last_index(size() - 1, size(), match);}
875 xtd::size find_last_index(xtd::size start_index, xtd::predicate<const type_t&> match) const {return find_last_index(start_index, start_index + 1, match);}
884 xtd::size find_last_index(xtd::size start_index, xtd::size count, xtd::predicate<const type_t&> match) const {
886 auto end_index = start_index - count;
887 for (auto index = start_index; index > end_index; --index)
888 if (match((*this)[index])) return index;
889 return npos;
890 }
891
900 void for_each(xtd::action<const type_t&> action) {
901 for (const auto& item : *this)
902 action(item);
903 }
904
907 virtual allocator_type get_allocator() const {return data_->items.get_allocator();}
908
912 virtual base_type& get_base_type() noexcept {return data_->items;}
915 virtual const base_type& get_base_type() const noexcept {return data_->items;}
916
919 enumerator<value_type> get_enumerator() const noexcept override {
920 return {new_ptr<__enumerator__>(*this, data_->version)};
921 }
922
935 list get_range(size_type index, size_type count) {
937
938 return list<type_t> {begin() + index, begin() + index + count};
939 }
940
944 size_type index_of(const type_t& value) const noexcept override {
945 if (count() == 0) return npos;
946 return index_of(value, 0, count());
947 }
948
954 virtual size_type index_of(const type_t& value, size_type index) const {return index_of(value, index, count() - index);}
955
962 virtual size_type index_of(const type_t& value, size_type index, size_type count) const {
965
966 for (auto i = index; i < index + count; ++i)
967 if (helpers::equator<type_t> {}(at(i), value)) return i;
968 return npos;
969 }
970
977 virtual iterator insert(const_iterator pos, const type_t& value) {
978 ++data_->version;
979 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), value));
980 }
981
987 virtual iterator insert(const_iterator pos, const type_t&& value) {
988 ++data_->version;
989 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), std::move(value)));
990 }
991
998 virtual iterator insert(const_iterator pos, size_type count, const type_t& value) {
999 ++data_->version;
1000 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), count, value));
1001 }
1002
1009 virtual iterator insert(const_iterator pos, size_type count, type_t&& value) {
1010 ++data_->version;
1011 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), count, std::move(value)));
1012 }
1013
1020 template<class input_iterator_t>
1021 iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last) {
1022 ++data_->version;
1023 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), first, last));
1024 }
1025
1031 virtual iterator insert(const_iterator pos, const std::initializer_list<type_t>& items) {
1032 ++data_->version;
1033 return to_type_iterator(data_->items.insert(to_const_base_type_iterator(pos), items.begin(), items.end()));
1034 }
1035
1041 void insert(size_type index, const type_t& value) override {
1043 insert(begin() + index, value);
1044 }
1045
1050 void insert(size_type index, type_t&& value) {
1052 insert(begin() + index, std::move(value));
1053 }
1054
1066
1067 // If the collection is this instance, it must be copied to avoid an infinite loop.
1068 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1069 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1070 insert(begin() + index, items.begin(), items.end());
1071 return;
1072 }
1073
1074 insert(begin() + index, enumerable.begin(), enumerable.end());
1075 }
1076
1086 virtual void insert_range(size_type index, const std::initializer_list<type_t>& items) {
1088 insert(begin() + index, items);
1089 }
1090
1092 template<class ienumerable_t>
1093 void insert_range(size_type index, const ienumerable_t& enumerable) {
1095
1096 // If the collection is this instance, it must be copied to avoid an infinite loop.
1097 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1098 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1099 insert(begin() + index, items.begin(), items.end());
1100 return;
1101 }
1102
1103 insert(begin() + index, enumerable.begin(), enumerable.end());
1104 }
1106
1110 size_type last_index_of(const type_t& value) const {
1111 if (size() == 0) return npos;
1112 return last_index_of(value, size() - 1, size());
1113 }
1114
1120 size_type last_index_of(const type_t& value, size_type index) const {
1121 return last_index_of(value, index, index + 1);
1122 }
1129 size_type last_index_of(const type_t& value, size_type index, size_type count) const {
1132
1133 for (auto i = index; i >= index - (count - 1); --i)
1134 if (value == data_->items[i]) return i;
1135
1136 return npos;
1137 }
1138
1142 virtual void pop_back() {
1143 ++data_->version;
1144 data_->items.pop_back();
1145 }
1146
1151 virtual void push_back(const type_t& value) {
1152 ++data_->version;
1153 data_->items.push_back(value);
1154 }
1159 virtual void push_back(type_t&& value) {
1160 ++data_->version;
1161 data_->items.push_back(std::move(value));
1162 }
1163
1169 bool remove(const type_t& item) override {
1170 if (count() == 0) return false;
1171 for (auto index = size_type {0}; index < count(); ++index) {
1172 if (!helpers::equator<type_t> {}(at(index), item)) continue;
1173 remove_at(index);
1174 return true;
1175 }
1176 return false;
1177 }
1178
1190 xtd::size remove_all(const xtd::predicate<const type_t&>& match) {
1191 auto count = xtd::size {0};
1192 auto iterator = data_->items.begin();
1193 while (iterator != data_->items.end())
1194 if (!match(*iterator)) iterator++;
1195 else {
1196 iterator = data_->items.erase(iterator);
1197 ++count;
1198 }
1199
1200 if (count) ++data_->version;
1201 return count;
1202 }
1203
1207 void remove_at(size_type index) override {
1209
1210 if (index == count() - 1) pop_back();
1211 else erase(begin() + index);
1212 }
1213
1222 virtual void remove_range(size_type index, size_type count) {
1224
1225 erase(begin() + index, begin() + index + count);
1226 }
1227
1233 virtual void reserve(size_type new_cap) {data_->items.reserve(new_cap);}
1234
1245 virtual void resize(size_type count, const value_type& value) {
1247 if (count == size()) return;
1248 ++data_->version;
1249 data_->items.resize(count, value);
1250 }
1251
1258 void reverse() {reverse(0, count());}
1268 void reverse(size_type index, size_type count) {
1270
1271 ++data_->version;
1272 auto poitions1 = index;
1273 auto position2 = (index + count) - 1;
1274 auto iterator1 = data_->items.begin() + poitions1;
1275 auto iterator2 = data_->items.begin() + position2;
1276
1277 while (poitions1++ < position2--)
1278 std::iter_swap(iterator1++, iterator2--);
1279 }
1280
1284 virtual void shrink_to_fit() {data_->items.shrink_to_fit();}
1285
1293 return list<type_t> {data_->items.begin() + start, data_->items.begin() + start + length};
1294 }
1295
1306
1313 ++data_->version;
1314 std::sort(data_->items.begin(), data_->items.end(), __comparison_comparer__ {comparison});
1315 }
1316
1323 void sort(const xtd::collections::generic::icomparer<type_t>& comparer) {
1324 sort(0, count(), comparer);
1325 }
1326
1335 void sort(xtd::size index, xtd::size count, const xtd::collections::generic::icomparer<type_t>& comparer) {
1337 auto first = data_->items.begin();
1338 auto last = data_->items.begin();
1339 std::advance(first, index);
1340 std::advance(last, index + count);
1341 ++data_->version;
1342 std::sort(first, last, __comparer__ {comparer});
1343 }
1344
1347 virtual void swap(list& other) noexcept {
1348 ++data_->version;
1349 data_->items.swap(other.data_->items);
1350 }
1351
1359 virtual xtd::array<value_type> to_array() const noexcept {return size() ? xtd::array<value_type>(data(), size()) : xtd::array<value_type> {};}
1360
1363 string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
1364
1385 virtual void trim_excess() {shrink_to_fit();}
1386
1398 bool true_for_all(xtd::predicate<const type_t&> match) const {
1399 for (const auto& item : *this)
1400 if (!match(item)) return false;
1401 return true;
1402 }
1404
1406
1411 list& operator =(const list& other) = default;
1415 list& operator =(list&& other) noexcept {
1416 data_->version = std::move(other.data_->version);
1417 data_->items = std::move(other.data_->items);
1418 return *this;
1419 }
1423 list& operator =(std::initializer_list<type_t>& items) {
1424 data_->version = 0;
1425 data_->items = items;
1426 return *this;
1427 }
1428
1433 const_reference operator [](size_type index) const override {return at(index);}
1438 reference operator [](size_type index) override {return at(index);}
1439
1442 operator const base_type& () const noexcept {return data_->items;}
1445 operator base_type& () noexcept {return data_->items;}
1447
1448 private:
1449 typename base_type::const_iterator to_const_base_type_iterator(const_iterator value) const noexcept {
1450 return ilist<type_t>::to_const_iterator(value, *this, data_->items);
1451 }
1452
1453 const_iterator to_const_type_iterator(typename base_type::const_iterator value) const noexcept {
1454 return ilist<type_t>::to_const_iterator(value, data_->items, *this);
1455 }
1456
1457 typename base_type::const_iterator to_base_type_iterator(const_iterator value) const noexcept {
1458 return ilist<type_t>::to_iterator(value, *this, data_->items);
1459 }
1460
1461 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
1462 return ilist<type_t>::to_iterator(value, *this, data_->items);
1463 }
1464
1465 const_iterator to_type_iterator(typename base_type::const_iterator value) const noexcept {
1466 return ilist<type_t>::to_iterator(value, data_->items, *this);
1467 }
1468
1469 iterator to_type_iterator(typename base_type::iterator value) noexcept {
1470 return ilist<type_t>::to_iterator(value, data_->items, *this);
1471 }
1472
1473 struct list_data {
1474 list_data() = default;
1475 explicit list_data(const allocator_type& alloc) noexcept : items(alloc) {}
1476 list_data(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : items(count, value, alloc) {}
1477 explicit list_data(size_type count, const allocator_type& alloc = allocator_type()) : items(count, alloc) {}
1478 template<class input_iterator_t>
1479 list_data(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : items(first, last, alloc) {}
1480 list_data(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : items(collection.begin(), collection.end(), alloc) {}
1481 list_data(const list& list) : items(list.data_->items), version(list.data_->version) {}
1482 list_data(const base_type& list) : items(list) {}
1483 list_data(const list& list, const allocator_type& alloc) : items(list.data_->items, alloc), version(list.data_->version) {}
1484 list_data(const base_type& list, const allocator_type& alloc) : items(list, alloc) {}
1485 list_data(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : items(items.begin(), items.end(), alloc) {}
1486 list_data(list&& other) : items(std::move(other.data_->items)), version(std::move(other.data_->version)) {other.data_->items.clear(); other.data_->version = 0;}
1487 list_data(base_type&& other) : items(std::move(other)) {other.clear();}
1488 list_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;}
1489 list_data(base_type&& other, const allocator_type& alloc) : items(std::move(other), alloc) {}
1490
1491 list_data(const list_data&) = default;
1492 list_data& operator =(const list_data&) = default;
1493
1494 base_type items;
1495 size_type version = 0;
1496 xtd::object sync_root;
1497 };
1498
1500 };
1501
1503 // C++17 deduction guides for xtd::collections::generic::list
1504 // {
1505 template<class type_t>
1506 list(std::initializer_list<type_t>) -> list<type_t, helpers::allocator<type_to_list_t<type_t >>>;
1507
1508 template<class type_t>
1509 list(const ienumerable<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t >>>;
1510
1511 template<class type_t>
1512 list(const ilist<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t >>>;
1513
1514 template<class type_t>
1515 list(const std::vector<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t >>>;
1516
1517 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1518 list(const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
1519
1520 template<class type_t>
1521 list(std::vector<type_t>&&) -> list<type_t, helpers::allocator<type_to_list_t<type_t >>>;
1522
1523 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1524 list(list<type_t, allocator_t>&&) -> list<type_t, allocator_t>;
1525 // }
1527 }
1528 }
1529}
1530
1533 template <class enumerable_t, class source_t>
1534 inline const xtd::collections::generic::list<source_t>& enumerable<enumerable_t, source_t>::to_list() const noexcept {
1535 return xtd::linq::enumerable::to_list(base());
1536 }
1537}
1538
1539namespace xtd::linq {
1540 template <class source_t>
1541 inline auto enumerable::to_list(const xtd::collections::generic::ienumerable<source_t>& source) noexcept {
1542 auto result = xtd::collections::generic::list<source_t> {};
1543 result = xtd::collections::generic::list<source_t> {source};
1544 return result;
1545 }
1546}
1548
Contains xtd::collections::generic::list definitions.
Contains xtd::action delegate.
Contains xtd::collections::generic::helpers::allocator alias.
Contains xtd::argument_exception exception.
Contains xtd::argument_out_of_range_exception exception.
Contains xtd::box_integer class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
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:246
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
result_type compare(const first_argument_type &x, const second_argument_type &y) const noexcept override
Compares two entities and returns a value indicating whether one is less than, equal to,...
Definition comparer.hpp:66
static const comparer< xtd::any_object > default_comparer
Definition comparer.hpp:50
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:148
virtual const_iterator begin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:141
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:152
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:156
const list< source_t > & to_list() const noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
typename xtd::collections::generic::extensions::enumerable_iterators< xtd::any_object, xtd::collections::generic::ienumerable< xtd::any_object > >::const_iterator const_iterator
Definition ienumerable.hpp:46
typename xtd::collections::generic::extensions::enumerable_iterators< xtd::any_object, xtd::collections::generic::ienumerable< xtd::any_object > >::iterator iterator
Definition ienumerable.hpp:44
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:79
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:1041
bool is_read_only() const noexcept override
Gets a value indicating whether the xtd::collections::generic::list <type_t> is read-only.
Definition list.hpp:388
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:354
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:479
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:555
list(base_type &&other)
Move constructor with specified base type list.
Definition list.hpp:228
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumerable.
Definition list.hpp:253
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:563
xtd::size binary_search(const type_t &item) const
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the default ...
Definition list.hpp:581
xtd::size binary_search(const type_t &item, const xtd::collections::generic::icomparer< type_t > &comparer) const
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the specifie...
Definition list.hpp:594
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.hpp:732
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:349
virtual const_base_type & items() const noexcept
Returns the underlying base type items.
Definition list.hpp:408
typename xtd::collections::generic::ienumerable< xtd::any_object >::iterator iterator
Definition list.hpp:144
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:415
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:689
virtual reference front()
Returns a reference to the first element in the container.
Definition list.hpp:374
list< output_t > convert_all(xtd::converter< output_t, const type_t & > converter) const
Converts the elements in the current xtd::colllections::generic::list <type_t> to another type,...
Definition list.hpp:649
const value_type * const_pointer
Definition list.hpp:142
const base_type const_base_type
Definition list.hpp:130
const xtd::object & sync_root() const noexcept override
Gets an object that can be used to synchronize access to the the xtd::collections::generic::list <typ...
Definition list.hpp:460
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.hpp:159
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:221
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition list.hpp:366
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:1064
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.hpp:529
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.hpp:429
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumerable.
Definition list.hpp:312
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:539
typename base_type::reverse_iterator reverse_iterator
Definition list.hpp:148
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.hpp:232
void copy_to(xtd::array< type_t > &array, size_type array_index) const override
Copies the entire xtd::colllections::generic::list <type_t> to a compatible one-dimensional array,...
Definition list.hpp:674
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:666
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:193
typename xtd::collections::generic::ienumerable< xtd::any_object >::const_iterator const_iterator
Definition list.hpp:146
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:358
void clear() override
Removes all elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:627
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.hpp:411
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.hpp:362
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.hpp:378
void insert(size_type index, type_t &&value)
Inserts an element into the xtd::collections::generic::list <type_t> at the specified index.
Definition list.hpp:1050
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:719
size_type last_index_of(const type_t &value) const
Determines the last index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:1110
typename xtd::collections::generic::helpers::allocator< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type > allocator_type
Definition list.hpp:126
bool is_synchronized() const noexcept override
Gets a value indicating whether access to the xtd::collections::generic::list <type_t> is synchronize...
Definition list.hpp:404
list(const list &list)
Default copy constructor with specified list.
Definition list.hpp:206
xtd::ptrdiff difference_type
Definition list.hpp:134
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:202
xtd::size binary_search(xtd::size index, xtd::size count, const type_t &item, const xtd::collections::generic::icomparer< type_t > &comparer) const
Searches a range of elements in the sorted xtd::collections::generic::list <type_t> for an element us...
Definition list.hpp:610
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:249
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.hpp:217
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.hpp:213
bool is_fixed_size() const noexcept override
Gets a value indicating whether the xtd::collections::generic::list <type_t> has a fixed size.
Definition list.hpp:383
xtd::size size_type
Definition list.hpp:132
virtual iterator insert(const_iterator pos, size_type count, type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:1009
const value_type & const_reference
Definition list.hpp:138
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition list.hpp:369
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:280
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.hpp:546
xtd::size ensure_capacity(xtd::size capacity)
Ensures that the capacity of this list is at least the specified capacity. If the current capacity is...
Definition list.hpp:727
std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Definition list.hpp:128
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:344
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp:339
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:183
list(list &&other)
Move constructor with specified list.
Definition list.hpp:225
typename base_type::const_reverse_iterator const_reverse_iterator
Definition list.hpp:150
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:433
value_type & reference
Definition list.hpp:136
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:1086
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:503
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:524
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:420
void add(type_t &&item)
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:493
iterator begin() noexcept override
Returns an iterator to the first element of the enumerable.
Definition list.hpp:256
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:303
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:437
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.hpp:977
virtual void resize(size_type count)
Determines the last index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:1239
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.hpp:209
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:424
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.hpp:236
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:513
value_type * pointer
Definition list.hpp:140
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumerable.
Definition list.hpp:316
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:1031
xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Definition list.hpp:152
bool contains(const type_t &value) const noexcept override
Determines whether an element is in the xtd::colllections::generic::list <type_t>.
Definition list.hpp:635
type_t value_type
Represents the list value type.
Definition list.hpp:124
virtual size_type index_of(const type_t &value, size_type index, size_type count) const
Erases the specified elements from the container.
Definition list.hpp:962
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:1021
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.hpp:709
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:187
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:998
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:987
virtual reference back()
Returns a reference to the last element in the container.
Definition list.hpp:245
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:38
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
static auto to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
Contains xtd::comparison delegate.
Contains xtd::converter alias.
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::comparer <type_t> class.
Contains xtd::collections::generic::ilist <type_t> interface.
generic::enumerator< xtd::any_object > enumerator
Supports a simple iteration over a non-generic collection.
Definition enumerator.hpp:28
generic::ilist< xtd::any_object > ilist
Represents a non-generic collection of objects that can be individually accessed by index.
Definition ilist.hpp:32
xtd::collections::generic::comparer< xtd::any_object > comparer
Exposes a method that compares two objects.
Definition comparer.hpp:25
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
xtd::delegate< int32(type_t x, type_t y)> comparison
Represents the method that compares two objects of the same type.
Definition comparison.hpp:33
xtd::delegate< output_t(input_t input)> converter
Represents a method that converts an object from one type to another type.
Definition converter.hpp:33
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:38
@ argument
The argument is not valid.
Definition exception_case.hpp:31
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:59
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:63
std::type_info type
Stores information about a type.
Definition type.hpp:23
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
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.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
xtd::func< bool, type_t > predicate
Represents a delegate that defines a set of criteria and determines whether the specified object meet...
Definition predicate.hpp:16
delegate< void(arguments_t...)> action
Represents a xtd::delegate that has variable parameters and does not return a value.
Definition action.hpp:20
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
@ start
Starting of a logical operation.
Definition trace_event_type.hpp:37
@ other
The operating system is other.
Definition platform_id.hpp:58
@ c
The C key.
Definition console_key.hpp:92
@ i
The I key.
Definition console_key.hpp:104
@ insert
The INS (INSERT) key.
Definition console_key.hpp:62
size_type
Specifies how rows or columns of user interface (UI) elements should be sized relative to their conta...
Definition size_type.hpp:22
Contains xtd::index_out_of_range_exception exception.
Contains xtd::intptr type.
Contains xtd::invalid_operation_exception exception.
Contains xtd::is method.
The xtd::extensions namespace contains interface extensions.
Definition collection_operators.hpp:13
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
virtual bool remove(const type_t &item)=0
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:41
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
const_reference at(size_type pos) const
Gets the specified element with bounds checking.
Definition read_only_span.hpp:255
read_only_span< type_t > slice() const
Forms a slice out of the current read_only_span starting at a specified index for a specified length.
Definition read_only_span.hpp:325
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
xtd::array< std::remove_cv_t< type_t > > to_array() const noexcept
Copies the contents of this read_only_span into a new array.
Definition read_only_span.hpp:368
Contains xtd::new_ptr method.
Contains xtd::object class.
Contains xtd::predicate delegate.
Contains xtd::ptr type.
Contains xtd::collections::object_model::read_only_collection class.
Contains xtd::string alias.
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:38