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 "../../literals.hpp"
24#include "../../object.hpp"
25#include "../../new_ptr.hpp"
26#include "../../predicate.hpp"
27#include "../../ptr.hpp"
28#include "../../string.hpp"
29#include <utility>
30#include <vector>
31
33namespace xtd {
35 namespace collections {
37 namespace generic {
79 template<class type_t, class allocator_t>
80 class list : public xtd::object, public xtd::collections::generic::ilist<type_t>, public xtd::iequatable<xtd::collections::generic::list<type_t, allocator_t>> {
81 struct __comparer__ {
82 __comparer__(const xtd::collections::generic::icomparer<type_t>& comparer) : comparer_(comparer) {}
83 bool operator()(const type_t& e1, const type_t& e2) const {return comparer_.compare(e1, e2) < 0;}
85 };
86
87 struct __comparison_comparer__ {
88 __comparison_comparer__(xtd::comparison<const type_t&> comparison) : comparison_(comparison) {}
89 bool operator()(const type_t& e1, const type_t& e2) const {return comparison_(e1, e2) < 0;}
91 };
92
93 struct __enumerator__ : public ienumerator<type_t> {
94 public:
95 explicit __enumerator__(const list& items, xtd::size version) : items_(items), version_(version) {}
96
97 const type_t& current() const override {
98 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
99 if (index_ < items_.count()) return items_[index_];
100 static thread_local auto default_value = value_type {};
101 return default_value;
102 }
103
104 bool move_next() override {
105 if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
106 return ++index_ < items_.count();
107 }
108
109 void reset() override {
110 version_ = items_.data_->version;
111 index_ = list::npos;
112 }
113
114 protected:
115 const list& items_;
116 xtd::size index_ = list::npos;
117 xtd::size version_ = 0;
118 };
119
120 public:
122
125 using value_type = type_t;
129 using base_type = std::vector<typename std::conditional<std::is_same<bool, value_type>::value, xtd::byte, value_type>::type, allocator_type>;
143 using const_pointer = const value_type*;
149 using reverse_iterator = typename base_type::reverse_iterator;
151 using const_reverse_iterator = typename base_type::const_reverse_iterator;
155
157
160 inline static constexpr size_type npos = xtd::collections::generic::ilist<type_t>::npos;
162
164
175 list() noexcept = default;
176
179 explicit list(const allocator_type& alloc) noexcept : data_(xtd::new_ptr<list_data>(alloc)) {}
184 list(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(count, value, alloc)) {}
188 explicit list(size_type count, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(count, alloc)) {}
193 template<class input_iterator_t>
194 list(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(first, last, alloc)) {}
203 list(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(collection, alloc)) {}
204
207 list(const list& list) : data_(xtd::new_ptr<list_data>(list)) {}
210 list(const base_type& list) : data_(xtd::new_ptr<list_data>(list)) {}
214 list(const list& list, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(list, alloc)) {}
218 list(const base_type& list, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(list, alloc)) {}
222 list(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : data_(xtd::new_ptr<list_data>(items, alloc)) {}
223
226 list(list&& other) : data_(xtd::new_ptr<list_data>(std::move(other))) {other.data_ = xtd::new_ptr<list_data>();}
229 list(base_type&& other) : data_(xtd::new_ptr<list_data>(std::move(other))) {other.clear();}
233 list(list&& other, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(std::move(other)), alloc) {other.data_ = xtd::new_ptr<list_data>();}
237 list(base_type&& other, const allocator_type& alloc) : data_(xtd::new_ptr<list_data>(std::move(other), alloc)) {other.items.clear();}
239
241
246 virtual reference back() {return at(count() - 1);}
250 virtual const_reference back() const {return at(count() - 1);}
251
254 const_iterator begin() const noexcept override {return ienumerable<value_type>::begin();}
257 iterator begin() noexcept override {return ienumerable<value_type>::begin();}
258
281 virtual size_type capacity() const noexcept {return data_->items.capacity();}
304 virtual void capacity(size_type value) {
306 if (value == capacity()) return;
307 if (value < capacity()) shrink_to_fit();
308 reserve(value);
309 }
310
313 const_iterator cbegin() const noexcept override {return ienumerable<value_type>::cbegin();}
314
317 const_iterator cend() const noexcept override {return ienumerable<value_type>::cend();}
318
340 size_type count() const noexcept override {return size();}
341
345 virtual const_reverse_iterator crbegin() const noexcept {return data_->items.crbegin();}
346
350 virtual const_reverse_iterator crend() const noexcept {return data_->items.crend();}
351
355 virtual pointer data() noexcept {return reinterpret_cast<pointer>(data_->items.data());}
359 virtual const_pointer data() const noexcept {return reinterpret_cast<const_pointer>(data_->items.data());}
360
363 virtual bool empty() const noexcept {return data_->items.empty();}
364
367 const_iterator end() const noexcept override {return ienumerable<value_type>::end();}
370 iterator end() noexcept override {return ienumerable<value_type>::end();}
371
375 virtual reference front() {return at(0);}
379 virtual const_reference front() const {return at(0);}
380
384 bool is_fixed_size() const noexcept override {return false;}
385
389 bool is_read_only() const noexcept override {return false;}
390
405 bool is_synchronized() const noexcept override {return false;}
406
409 virtual const_base_type& items() const noexcept {return data_->items;}
412 virtual base_type& items() noexcept {return data_->items;}
413
416 virtual size_type max_size() const noexcept {return data_->items.max_size();}
417
421 virtual reverse_iterator rbegin() noexcept {return data_->items.rbegin();}
425 virtual const_reverse_iterator rbegin() const noexcept {return data_->items.rbegin();}
426
430 virtual reverse_iterator rend() noexcept {return data_->items.rend();}
434 virtual const_reverse_iterator rend() const noexcept {return data_->items.rend();}
435
438 virtual size_type size() const noexcept {return data_->items.size();}
439
461 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
463
465
480 void add(const type_t& item) override {push_back(item);}
494 void add(type_t&& item) {push_back(std::move(item));}
495
505
514 void add_range(std::initializer_list<type_t> il) {insert_range(count(), il);}
515
517 template<class enumerable_t>
518 void add_range(const enumerable_t& enumerable) {insert_range(count(), enumerable);}
520
526
530 void assign(size_type count, const type_t& value) {
531 ++data_->version;
532 data_->items.assign(count, value);
533 }
534
539 template<class input_iterator_t>
540 void assign(input_iterator_t first, input_iterator_t last) {
541 ++data_->version;
542 data_->items.assign(first, last);
543 }
544
547 virtual void assign(std::initializer_list<type_t> items) {
548 ++data_->version;
549 data_->items.assign(items.begin(), items.end());
550 }
551
556 virtual reference at(size_type index) {
558 return reinterpret_cast<reference>(data_->items.at(index));
559 }
560
564 virtual const_reference at(size_type index) const {
566 return reinterpret_cast<const_reference>(data_->items.at(index));
567 }
568
583
596
613 auto first = data_->items.begin();
614 auto last = data_->items.begin();
615 std::advance(first, index);
616 std::advance(last, index + count);
617 auto position = std::lower_bound(first, last, item, __comparer__{comparer});
618
619 if (position != data_->items.end() && !comparer.compare(item, *position))
620 return std::distance(data_->items.begin(), position);
621 return ~std::distance(data_->items.begin(), position);
622 }
623
628 void clear() override {
629 ++data_->version;
630 data_->items.clear();
631 }
632
636 bool contains(const type_t& value) const noexcept override {
637 for (const auto& item : data_->items)
638 if (helpers::equator<type_t> {}(reinterpret_cast<const type_t&>(item), value)) return true;
639 return false;
640 }
641
649 template<class output_t>
651 auto result = list<output_t> {};
652 for (const auto& item : *this)
653 result.add(converter(item));
654 return result;
655 }
656
667 virtual void copy_to(xtd::array<type_t>& array) const {copy_to(0, array, 0, count());}
675 void copy_to(xtd::array<type_t>& array, size_type array_index) const override {copy_to(0, array, array_index, count());}
690 virtual void copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const {
692 auto i = size_type {0}, c = size_type {0};
693 for (const type_t& item : *this) {
694 if (i >= index + count) return;
695 if (i >= index) {
696 array[array_index + c] = item;
697 c += 1;
698 }
699 i += 1;
700 }
701 }
702
709 template<class ...args_t>
710 iterator emplace(const_iterator pos, args_t&&... args) {
711 ++data_->version;
712 return to_type_iterator(data_->items.emplace(to_base_type_iterator(pos), std::forward<args_t>(args)...));
713 }
714
719 template<class ...args_t>
720 reference emplace_back(args_t&&... args) {
721 ++data_->version;
722 return data_->items.emplace_back(std::forward<args_t>(args)...);
723 }
724
729 data_->items.reserve(capacity);
730 return this->capacity();
731 }
732
733 bool equals(const object& obj) const noexcept override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>&>(obj));}
734 bool equals(const list& rhs) const noexcept override {
735 if (count() != rhs.count()) return false;
736 for (size_type i = 0; i < count(); i++)
737 if (!helpers::equator<type_t> {}(at(i), rhs.at(i))) return false;
738 return data_->version == rhs.data_->version;
739 }
740
748 virtual iterator erase(const_iterator pos) {
749 ++data_->version;
750 return to_type_iterator(data_->items.erase(to_base_type_iterator(pos)));
751 }
761 ++data_->version;
762 return to_type_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
763 }
764
776 bool exists(xtd::predicate<const type_t&> match) const {
777 for (const auto& item : *this)
778 if (match(item)) return true;
779 return false;
780 }
781
793 type_t find(xtd::predicate<const type_t&> match) const {
794 for (const auto& item : *this)
795 if (match(item)) return item;
796 return type_t {};
797 }
798
810 list<type_t> find_all(xtd::predicate<const type_t&> match) const {
811 auto result = list<type_t> {};
812 for (const auto& item : *this)
813 if (match(item)) result.add(item);
814 return result;
815 }
816
822 xtd::size find_index(xtd::predicate<const type_t&> match) const {return find_index(0, size(), match);}
830 xtd::size find_index(xtd::size start_index, xtd::predicate<const type_t&> match) const {return find_index(start_index, size() - start_index, match);}
839 xtd::size find_index(xtd::size start_index, xtd::size count, xtd::predicate<const type_t&> match) const {
841 for (auto index = start_index; index < start_index + count; ++index)
842 if (match((*this)[index])) return index;
843 return npos;
844 }
845
857 type_t find_last(xtd::predicate<const type_t&> match) const {
858 for (auto iterator = rbegin(); iterator != rend(); ++iterator)
859 if (match(*iterator)) return *iterator;
860 return type_t {};
861 }
862
868 xtd::size find_last_index(xtd::predicate<const type_t&> match) const {return find_last_index(size() - 1, size(), match);}
876 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);}
885 xtd::size find_last_index(xtd::size start_index, xtd::size count, xtd::predicate<const type_t&> match) const {
887 auto end_index = start_index - count;
888 for (auto index = start_index; index > end_index; --index)
889 if (match((*this)[index])) return index;
890 return npos;
891 }
892
901 void for_each(xtd::action<const type_t&> action) {
902 for (const auto& item : *this)
903 action(item);
904 }
905
908 virtual allocator_type get_allocator() const {return data_->items.get_allocator();}
909
913 virtual base_type& get_base_type() noexcept {return data_->items;}
916 virtual const base_type& get_base_type() const noexcept {return data_->items;}
917
920 enumerator<value_type> get_enumerator() const noexcept override {
921 return {new_ptr<__enumerator__>(*this, data_->version)};
922 }
923
936 list get_range(size_type index, size_type count) {
938
939 return list<type_t> {begin() + index, begin() + index + count};
940 }
941
945 size_type index_of(const type_t& value) const noexcept override {
946 if (count() == 0) return npos;
947 return index_of(value, 0, count());
948 }
949
955 virtual size_type index_of(const type_t& value, size_type index) const {return index_of(value, index, count() - index);}
956
963 virtual size_type index_of(const type_t& value, size_type index, size_type count) const {
966
967 for (auto i = index; i < index + count; ++i)
968 if (helpers::equator<type_t> {}(at(i), value)) return i;
969 return npos;
970 }
971
978 virtual iterator insert(const_iterator pos, const type_t& value) {
979 ++data_->version;
980 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), value));
981 }
982
988 virtual iterator insert(const_iterator pos, const type_t&& value) {
989 ++data_->version;
990 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), std::move(value)));
991 }
992
999 virtual iterator insert(const_iterator pos, size_type count, const type_t& value) {
1000 ++data_->version;
1001 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), count, value));
1002 }
1003
1010 virtual iterator insert(const_iterator pos, size_type count, type_t&& value) {
1011 ++data_->version;
1012 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), count, std::move(value)));
1013 }
1014
1021 template<class input_iterator_t>
1022 iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last) {
1023 ++data_->version;
1024 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
1025 }
1026
1032 virtual iterator insert(const_iterator pos, const std::initializer_list<type_t>& items) {
1033 ++data_->version;
1034 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), items.begin(), items.end()));
1035 }
1036
1042 void insert(size_type index, const type_t& value) override {
1044 insert(begin() + index, value);
1045 }
1046
1051 void insert(size_type index, type_t&& value) {
1053 insert(begin() + index, std::move(value));
1054 }
1055
1067
1068 // If the collection is this instance, it must be copied to avoid an infinite loop.
1069 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1070 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1071 insert(begin() + index, items.begin(), items.end());
1072 return;
1073 }
1074
1075 insert(begin() + index, enumerable.begin(), enumerable.end());
1076 }
1077
1087 virtual void insert_range(size_type index, const std::initializer_list<type_t>& items) {
1089 insert(begin() + index, items);
1090 }
1091
1093 template<class ienumerable_t>
1094 void insert_range(size_type index, const ienumerable_t& enumerable) {
1096
1097 // If the collection is this instance, it must be copied to avoid an infinite loop.
1098 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1099 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1100 insert(begin() + index, items.begin(), items.end());
1101 return;
1102 }
1103
1104 insert(begin() + index, enumerable.begin(), enumerable.end());
1105 }
1107
1111 size_type last_index_of(const type_t& value) const {
1112 if (size() == 0) return npos;
1113 return last_index_of(value, size() - 1, size());
1114 }
1115
1121 size_type last_index_of(const type_t& value, size_type index) const {
1122 return last_index_of(value, index, index + 1);
1123 }
1130 size_type last_index_of(const type_t& value, size_type index, size_type count) const {
1133
1134 for (auto i = index; i >= index - (count - 1); --i)
1135 if (value == data_->items[i]) return i;
1136
1137 return npos;
1138 }
1139
1143 virtual void pop_back() {
1144 ++data_->version;
1145 data_->items.pop_back();
1146 }
1147
1152 virtual void push_back(const type_t& value) {
1153 ++data_->version;
1154 data_->items.push_back(value);
1155 }
1160 virtual void push_back(type_t&& value) {
1161 ++data_->version;
1162 data_->items.push_back(std::move(value));
1163 }
1164
1170 bool remove(const type_t& item) override {
1171 if (count() == 0) return false;
1172 for (auto index = size_type {0}; index < count(); ++index) {
1173 if (!helpers::equator<type_t> {}(at(index), item)) continue;
1174 remove_at(index);
1175 return true;
1176 }
1177 return false;
1178 }
1179
1191 xtd::size remove_all(const xtd::predicate<const type_t&>& match) {
1192 auto count = xtd::size {0};
1193 auto iterator = data_->items.begin();
1194 while (iterator != data_->items.end())
1195 if (!match(*iterator)) iterator++;
1196 else {
1197 iterator = data_->items.erase(iterator);
1198 ++count;
1199 }
1200
1201 if (count) ++data_->version;
1202 return count;
1203 }
1204
1208 void remove_at(size_type index) override {
1210
1211 if (index == count() - 1) pop_back();
1212 else erase(begin() + index);
1213 }
1214
1223 virtual void remove_range(size_type index, size_type count) {
1225
1226 erase(begin() + index, begin() + index + count);
1227 }
1228
1234 virtual void reserve(size_type new_cap) {data_->items.reserve(new_cap);}
1235
1246 virtual void resize(size_type count, const value_type& value) {
1248 if (count == size()) return;
1249 ++data_->version;
1250 data_->items.resize(count, value);
1251 }
1252
1259 void reverse() {reverse(0, count());}
1269 void reverse(size_type index, size_type count) {
1271
1272 ++data_->version;
1273 auto poitions1 = index;
1274 auto position2 = (index + count) - 1;
1275 auto iterator1 = data_->items.begin() + poitions1;
1276 auto iterator2 = data_->items.begin() + position2;
1277
1278 while (poitions1++ < position2--)
1279 std::iter_swap(iterator1++, iterator2--);
1280 }
1281
1285 virtual void shrink_to_fit() {data_->items.shrink_to_fit();}
1286
1294 return list<type_t> {data_->items.begin() + start, data_->items.begin() + start + length};
1295 }
1296
1307
1314 ++data_->version;
1315 std::sort(data_->items.begin(), data_->items.end(), __comparison_comparer__ {comparison});
1316 }
1317
1324 void sort(const xtd::collections::generic::icomparer<type_t>& comparer) {
1325 sort(0, count(), comparer);
1326 }
1327
1336 void sort(xtd::size index, xtd::size count, const xtd::collections::generic::icomparer<type_t>& comparer) {
1338 auto first = data_->items.begin();
1339 auto last = data_->items.begin();
1340 std::advance(first, index);
1341 std::advance(last, index + count);
1342 ++data_->version;
1343 std::sort(first, last, __comparer__ {comparer});
1344 }
1345
1348 virtual void swap(list& other) noexcept {
1349 ++data_->version;
1350 data_->items.swap(other.data_->items);
1351 }
1352
1360 virtual xtd::array<value_type> to_array() const noexcept {return size() ? xtd::array<value_type>(data(), size()) : xtd::array<value_type> {};}
1361
1364 string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
1365
1386 virtual void trim_excess() {shrink_to_fit();}
1387
1399 bool true_for_all(xtd::predicate<const type_t&> match) const {
1400 for (const auto& item : *this)
1401 if (!match(item)) return false;
1402 return true;
1403 }
1405
1407
1412 list& operator =(const list& other) = default;
1416 list& operator =(list&& other) noexcept {
1417 data_->version = std::move(other.data_->version);
1418 data_->items = std::move(other.data_->items);
1419 return *this;
1420 }
1424 list& operator =(std::initializer_list<type_t>& items) {
1425 data_->version = 0;
1426 data_->items = items;
1427 return *this;
1428 }
1429
1434 const_reference operator [](size_type index) const override {return at(index);}
1439 reference operator [](size_type index) override {return at(index);}
1440
1443 operator const base_type&() const noexcept {return data_->items;}
1446 operator base_type&() noexcept {return data_->items;}
1448
1449 private:
1450 typename base_type::const_iterator to_base_type_iterator(const_iterator value) const noexcept {
1451 return ilist<type_t>::to_iterator(value, *this, data_->items);
1452 }
1453
1454 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
1455 return ilist<type_t>::to_iterator(value, *this, data_->items);
1456 }
1457
1458 const_iterator to_type_iterator(typename base_type::const_iterator value) const noexcept {
1459 return ilist<type_t>::to_iterator(value, data_->items, *this);
1460 }
1461
1462 iterator to_type_iterator(typename base_type::iterator value) noexcept {
1463 return ilist<type_t>::to_iterator(value, data_->items, *this);
1464 }
1465
1466 struct list_data {
1467 list_data() = default;
1468 explicit list_data(const allocator_type& alloc) noexcept : items(alloc) {}
1469 list_data(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : items(count, value, alloc) {}
1470 explicit list_data(size_type count, const allocator_type& alloc = allocator_type()) : items(count, alloc) {}
1471 template<class input_iterator_t>
1472 list_data(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : items(first, last, alloc) {}
1473 list_data(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : items(collection.begin(), collection.end(), alloc) {}
1474 list_data(const list& list) : items(list.data_->items), version(list.data_->version) {}
1475 list_data(const base_type& list) : items(list) {}
1476 list_data(const list& list, const allocator_type& alloc) : items(list.data_->items, alloc), version(list.data_->version) {}
1477 list_data(const base_type& list, const allocator_type& alloc) : items(list, alloc) {}
1478 list_data(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : items(items.begin(), items.end(), alloc) {}
1479 list_data(list&& other) : items(std::move(other.data_->items)), version(std::move(other.data_->version)) {other.data_->items.clear(); other.data_->version = 0;}
1480 list_data(base_type&& other) : items(std::move(other)) {other.clear();}
1481 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;}
1482 list_data(base_type&& other, const allocator_type& alloc) : items(std::move(other), alloc) {}
1483
1484 list_data(const list_data&) = default;
1485 list_data& operator =(const list_data&) = default;
1486
1487 base_type items;
1488 size_type version = 0;
1489 xtd::object sync_root;
1490 };
1491
1493 };
1494
1496 // C++17 deduction guides for xtd::collections::generic::list
1497 // {
1498 template<class type_t>
1499 list(std::initializer_list<type_t>) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1500
1501 template<class type_t>
1502 list(const ienumerable<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1503
1504 template<class type_t>
1505 list(const ilist<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1506
1507 template<class type_t>
1508 list(const std::vector<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1509
1510 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1511 list(const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
1512
1513 template<class type_t>
1514 list(std::vector<type_t>&&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1515
1516 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1517 list(list<type_t, allocator_t>&&) -> list<type_t, allocator_t>;
1518 // }
1520 }
1521 }
1522}
1523
1526 template <class enumerable_t, class source_t>
1527 inline const xtd::collections::generic::list<source_t>& enumerable<enumerable_t, source_t>::to_list() const noexcept {
1528 return xtd::linq::enumerable::to_list(base());
1529 }
1530}
1531
1532namespace xtd::linq {
1533 template <class source_t>
1534 inline const xtd::collections::generic::list<source_t>& enumerable::to_list(const xtd::collections::generic::ienumerable<source_t>& source) noexcept {
1535 static thread_local auto result = xtd::collections::generic::list<source_t> {};
1536 result = xtd::collections::generic::list<source_t> {source};
1537 return result;
1538 }
1539}
1541
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:229
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 end() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.hpp:170
virtual const_iterator begin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:155
virtual const_iterator cbegin() const
Returns an iterator to the first element of the enumarable.
Definition enumerable_iterators.hpp:162
virtual const_iterator cend() const
Returns an iterator to the element following the last element of the enumarable.
Definition enumerable_iterators.hpp:166
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:80
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:1042
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:389
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:355
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:480
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:556
list(base_type &&other)
Move constructor with specified base type list.
Definition list.hpp:229
const_iterator begin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:254
virtual const_reference at(size_type index) const
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:564
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:582
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:595
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.hpp:733
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:350
virtual const_base_type & items() const noexcept
Returns the underlying base type items.
Definition list.hpp:409
typename xtd::collections::generic::ienumerable< xtd::any_object >::iterator iterator
Definition list.hpp:145
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:416
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:690
virtual reference front()
Returns a reference to the first element in the container.
Definition list.hpp:375
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:650
const value_type * const_pointer
Definition list.hpp:143
const base_type const_base_type
Definition list.hpp:131
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:461
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition list.hpp:160
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:222
const_iterator end() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp:367
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:1065
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.hpp:530
virtual reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector....
Definition list.hpp:430
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:313
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:540
typename base_type::reverse_iterator reverse_iterator
Definition list.hpp:149
list(list &&other, const allocator_type &alloc)
Move constructor with specified list, and allocator.
Definition list.hpp:233
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:675
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:667
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:194
typename xtd::collections::generic::ienumerable< xtd::any_object >::const_iterator const_iterator
Definition list.hpp:147
virtual const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:359
void clear() override
Removes all elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:628
virtual base_type & items() noexcept
Returns the underlying base type items.
Definition list.hpp:412
virtual bool empty() const noexcept
Checks if the container has no elements, i.e. whether xtd::collections::generic::list::begin() == xtd...
Definition list.hpp:363
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.hpp:379
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:1051
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:720
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:1111
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:127
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:405
list(const list &list)
Default copy constructor with specified list.
Definition list.hpp:207
xtd::ptrdiff difference_type
Definition list.hpp:135
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:203
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:611
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:250
list(const base_type &list, const allocator_type &alloc)
Default copy constructor with specified base type list, and allocator.
Definition list.hpp:218
list(const list &list, const allocator_type &alloc)
Default copy constructor with specified list, and allocator.
Definition list.hpp:214
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:384
xtd::size size_type
Definition list.hpp:133
virtual iterator insert(const_iterator pos, size_type count, type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:1010
const value_type & const_reference
Definition list.hpp:139
iterator end() noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp:370
virtual size_type capacity() const noexcept
Gets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:281
virtual void assign(std::initializer_list< type_t > items)
Replaces the contents with the elements from the initializer list items.
Definition list.hpp:547
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:728
std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Definition list.hpp:129
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:345
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp:340
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:184
list(list &&other)
Move constructor with specified list.
Definition list.hpp:226
typename base_type::const_reverse_iterator const_reverse_iterator
Definition list.hpp:151
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:434
value_type & reference
Definition list.hpp:137
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:1087
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:504
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:525
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:421
void add(type_t &&item)
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:494
iterator begin() noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:257
virtual void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:304
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:438
virtual iterator insert(const_iterator pos, const type_t &value)
Inserts elements at the specified location in the container.
Definition list.hpp:978
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:1240
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.hpp:210
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:425
list(base_type &&other, const allocator_type &alloc)
Move constructor with specified base tyoe list, and allocator.
Definition list.hpp:237
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:514
value_type * pointer
Definition list.hpp:141
const_iterator cend() const noexcept override
Returns an iterator to the element following the last element of the enumarable.
Definition list.hpp:317
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:1032
xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Definition list.hpp:153
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:636
type_t value_type
Represents the list value type.
Definition list.hpp:125
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:963
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:1022
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.hpp:710
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:188
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:999
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:988
virtual reference back()
Returns a reference to the last element in the container.
Definition list.hpp:246
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 const list< source_t > & 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
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:365
delegate< void(arguments_t...)> action
Represents a xtd::delegate that has variable parameters and does not return a value.
Definition action.hpp:20
@ 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.
Contains xtd literals.
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