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__
10#include "../../internal/__list_definition.hpp"
11#undef __XTD_CORE_INTERNAL__
12#include "../object_model/read_only_collection.hpp"
13#include "../../action.hpp"
14#include "../../argument_exception.hpp"
15#include "../../argument_out_of_range_exception.hpp"
16#include "../../box_integer.hpp"
17#include "../../comparison.hpp"
18#include "../../converter.hpp"
19#include "../../index_out_of_range_exception.hpp"
20#include "../../invalid_operation_exception.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
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);}
481
491
500 void add_range(std::initializer_list<type_t> il) {insert_range(count(), il);}
501
503 template<class enumerable_t>
504 void add_range(const enumerable_t& enumerable) {insert_range(count(), enumerable);}
506
511 read_only_collection as_read_only() const noexcept {return read_only_collection {new_ptr<list<value_type>>(*this)};}
512
516 void assign(size_type count, const type_t& value) {
517 ++data_->version;
518 data_->items.assign(count, value);
519 }
520
525 template<class input_iterator_t>
526 void assign(input_iterator_t first, input_iterator_t last) {
527 ++data_->version;
528 data_->items.assign(first, last);
529 }
530
533 virtual void assign(std::initializer_list<type_t> items) {
534 clear();
535 for (auto item : items)
536 push_back(item);
537 }
538
543 virtual reference at(size_type index) {
545 return reinterpret_cast<reference>(data_->items.at(index));
546 }
551 virtual const_reference at(size_type index) const {
553 return reinterpret_cast<const_reference>(data_->items.at(index));
554 }
555
570
583
600 auto first = data_->items.begin();
601 auto last = data_->items.begin();
602 std::advance(first, index);
603 std::advance(last, index + count);
604 auto position = std::lower_bound(first, last, item, __comparer__{comparer});
605
606 if (position != data_->items.end() && !comparer.compare(item, *position))
607 return std::distance(data_->items.begin(), position);
608 return ~std::distance(data_->items.begin(), position);
609 }
610
615 void clear() override {
616 ++data_->version;
617 data_->items.clear();
618 }
619
623 bool contains(const type_t& value) const noexcept override {
624 for (const auto& item : data_->items)
625 if (helpers::equator<type_t> {}(reinterpret_cast<const type_t&>(item), value)) return true;
626 return false;
627 }
628
636 template<class output_t>
638 auto result = list<output_t> {};
639 for (const auto& item : *this)
640 result.add(converter(item));
641 return result;
642 }
643
654 virtual void copy_to(xtd::array<type_t>& array) const {copy_to(0, array, 0, count());}
662 void copy_to(xtd::array<type_t>& array, size_type array_index) const override {copy_to(0, array, array_index, count());}
677 virtual void copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const {
679 auto i = size_type {0}, c = size_type {0};
680 for (const type_t& item : *this) {
681 if (i >= index + count) return;
682 if (i >= index) {
683 array[array_index + c] = item;
684 c += 1;
685 }
686 i += 1;
687 }
688 }
689
696 template<class ...args_t>
697 iterator emplace(const_iterator pos, args_t&&... args) {
698 ++data_->version;
699 return to_type_iterator(data_->items.emplace(to_base_type_iterator(pos), std::forward<args_t>(args)...));
700 }
701
706 template<class ...args_t>
707 reference emplace_back(args_t&&... args) {
708 ++data_->version;
709 return data_->items.emplace_back(std::forward<args_t>(args)...);
710 }
711
716 data_->items.reserve(capacity);
717 return this->capacity();
718 }
719
720 bool equals(const object& obj) const noexcept override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>&>(obj));}
721 bool equals(const list& rhs) const noexcept override {
722 if (count() != rhs.count()) return false;
723 for (size_type i = 0; i < count(); i++)
724 if (!helpers::equator<type_t> {}(at(i), rhs.at(i))) return false;
725 return data_->version == rhs.data_->version;
726 }
727
736 ++data_->version;
737 return to_type_iterator(data_->items.erase(to_base_type_iterator(pos)));
738 }
748 ++data_->version;
749 return to_type_iterator(data_->items.erase(to_base_type_iterator(first), to_base_type_iterator(last)));
750 }
751
764 for (const auto& item : *this)
765 if (match(item)) return true;
766 return false;
767 }
768
781 for (const auto& item : *this)
782 if (match(item)) return item;
783 return type_t {};
784 }
785
798 auto result = list<type_t> {};
799 for (const auto& item : *this)
800 if (match(item)) result.add(item);
801 return result;
802 }
803
817 xtd::size find_index(xtd::size start_index, xtd::predicate<const type_t&> match) const {return find_index(start_index, size() - start_index, match);}
828 for (auto index = start_index; index < start_index + count; ++index)
829 if (match((*this)[index])) return index;
830 return npos;
831 }
832
845 for (auto iterator = rbegin(); iterator != rend(); ++iterator)
846 if (match(*iterator)) return *iterator;
847 return type_t {};
848 }
849
863 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);}
874 auto end_index = start_index - count;
875 for (auto index = start_index; index > end_index; --index)
876 if (match((*this)[index])) return index;
877 return npos;
878 }
879
889 for (const auto& item : *this)
890 action(item);
891 }
892
895 virtual allocator_type get_allocator() const {return data_->items.get_allocator();}
896
900 virtual base_type& get_base_type() noexcept {return data_->items;}
903 virtual const base_type& get_base_type() const noexcept {return data_->items;}
904
907 enumerator<value_type> get_enumerator() const noexcept override {
908 return {new_ptr<__enumerator__>(*this, data_->version)};
909 }
910
925
926 return list<type_t> {begin() + index, begin() + index + count};
927 }
928
932 size_type index_of(const type_t& value) const noexcept override {
933 if (count() == 0) return npos;
934 return index_of(value, 0, count());
935 }
936
942 virtual size_type index_of(const type_t& value, size_type index) const {return index_of(value, index, count() - index);}
943
950 virtual size_type index_of(const type_t& value, size_type index, size_type count) const {
953
954 for (auto i = index; i < index + count; ++i)
955 if (helpers::equator<type_t> {}(at(i), value)) return i;
956 return npos;
957 }
958
965 virtual iterator insert(const_iterator pos, const type_t& value) {
966 ++data_->version;
967 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), value));
968 }
975 virtual iterator insert(const_iterator pos, const type_t&& value) {
976 ++data_->version;
977 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), value));
978 }
986 virtual iterator insert(const_iterator pos, size_type count, const type_t& value) {
987 ++data_->version;
988 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), count, value));
989 }
997 template<class input_iterator_t>
998 iterator insert(const_iterator pos, input_iterator_t first, input_iterator_t last) {
999 ++data_->version;
1000 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), first, last));
1001 }
1008 virtual iterator insert(const_iterator pos, const std::initializer_list<type_t>& items) {
1009 ++data_->version;
1010 return to_type_iterator(data_->items.insert(to_base_type_iterator(pos), items.begin(), items.end()));
1011 }
1012
1018 void insert(size_type index, const type_t& value) override {
1020 insert(begin() + index, value);
1021 }
1022
1034
1035 // If the collection is this instance, it must be copied to avoid an infinite loop.
1036 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1037 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1038 insert(begin() + index, items.begin(), items.end());
1039 return;
1040 }
1041
1042 insert(begin() + index, enumerable.begin(), enumerable.end());
1043 }
1044
1054 virtual void insert_range(size_type index, const std::initializer_list<type_t>& items) {
1056 insert(begin() + index, items);
1057 }
1058
1060 template<class ienumerable_t>
1061 void insert_range(size_type index, const ienumerable_t& enumerable) {
1063
1064 // If the collection is this instance, it must be copied to avoid an infinite loop.
1065 if (reinterpret_cast<xtd::intptr>(&enumerable) == reinterpret_cast<xtd::intptr>(this)) {
1066 auto items = list<type_t>(enumerable.begin(), enumerable.end());
1067 insert(begin() + index, items.begin(), items.end());
1068 return;
1069 }
1070
1071 insert(begin() + index, enumerable.begin(), enumerable.end());
1072 }
1074
1078 size_type last_index_of(const type_t& value) const {
1079 if (size() == 0) return npos;
1080 return last_index_of(value, size() - 1, size());
1081 }
1082
1088 size_type last_index_of(const type_t& value, size_type index) const {
1089 return last_index_of(value, index, index + 1);
1090 }
1097 size_type last_index_of(const type_t& value, size_type index, size_type count) const {
1100
1101 for (auto i = index; i >= index - (count - 1); --i)
1102 if (value == data_->items[i]) return i;
1103
1104 return npos;
1105 }
1106
1110 virtual void pop_back() {
1111 ++data_->version;
1112 data_->items.pop_back();
1113 }
1114
1119 virtual void push_back(const type_t& value) {
1120 ++data_->version;
1121 data_->items.push_back(value);
1122 }
1127 virtual void push_back(type_t&& value) {
1128 ++data_->version;
1129 data_->items.push_back(value);
1130 }
1131
1137 bool remove(const type_t& item) override {
1138 if (count() == 0) return false;
1139 for (auto index = size_type {0}; index < count(); ++index) {
1140 if (!helpers::equator<type_t> {}(at(index), item)) continue;
1141 remove_at(index);
1142 return true;
1143 }
1144 return false;
1145 }
1146
1159 auto count = xtd::size {0};
1160 auto iterator = data_->items.begin();
1161 while (iterator != data_->items.end())
1162 if (!match(*iterator)) iterator++;
1163 else {
1164 iterator = data_->items.erase(iterator);
1165 ++count;
1166 }
1167
1168 if (count) ++data_->version;
1169 return count;
1170 }
1171
1175 void remove_at(size_type index) override {
1177
1178 if (index == count() - 1) pop_back();
1179 else erase(begin() + index);
1180 }
1181
1190 virtual void remove_range(size_type index, size_type count) {
1192
1193 erase(begin() + index, begin() + index + count);
1194 }
1195
1201 virtual void reserve(size_type new_cap) {data_->items.reserve(new_cap);}
1202
1213 virtual void resize(size_type count, const value_type& value) {
1215 if (count == size()) return;
1216 ++data_->version;
1217 data_->items.resize(count, value);
1218 }
1219
1226 void reverse() {reverse(0, count());}
1238
1239 ++data_->version;
1240 auto poitions1 = index;
1241 auto position2 = (index + count) - 1;
1242 auto iterator1 = data_->items.begin() + poitions1;
1243 auto iterator2 = data_->items.begin() + position2;
1244
1245 while (poitions1++ < position2--)
1246 std::iter_swap(iterator1++, iterator2--);
1247 }
1248
1252 virtual void shrink_to_fit() {data_->items.shrink_to_fit();}
1253
1259 list<type_t> slice(size_type start, size_type length) const {
1261 return list<type_t> {data_->items.begin() + start, data_->items.begin() + start + length};
1262 }
1263
1274
1281 ++data_->version;
1282 std::sort(data_->items.begin(), data_->items.end(), __comparison_comparer__ {comparison});
1283 }
1284
1292 sort(0, count(), comparer);
1293 }
1294
1305 auto first = data_->items.begin();
1306 auto last = data_->items.begin();
1307 std::advance(first, index);
1308 std::advance(last, index + count);
1309 ++data_->version;
1310 std::sort(first, last, __comparer__ {comparer});
1311 }
1312
1315 virtual void swap(list& other) noexcept {
1316 ++data_->version;
1317 data_->items.swap(other.data_->items);
1318 }
1319
1328
1331 string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
1332
1353 virtual void trim_excess() {shrink_to_fit();}
1354
1367 for (const auto& item : *this)
1368 if (!match(item)) return false;
1369 return true;
1370 }
1372
1374
1379 list& operator =(const list& other) = default;
1383 list& operator =(list&& other) noexcept {
1384 data_->version = std::move(other.data_->version);
1385 data_->items = std::move(other.data_->items);
1386 return *this;
1387 }
1391 list& operator =(std::initializer_list<type_t>& items) {
1392 data_->version = 0;
1393 data_->items = items;
1394 return *this;
1395 }
1396
1401 const_reference operator [](size_type index) const override {return at(index);}
1406 reference operator [](size_type index) override {return at(index);}
1407
1410 operator const base_type&() const noexcept {return data_->items;}
1413 operator base_type&() noexcept {return data_->items;}
1415
1416 private:
1417 typename base_type::const_iterator to_base_type_iterator(const_iterator value) const noexcept {
1418 return ilist<type_t>::to_iterator(value, *this, data_->items);
1419 }
1420
1421 typename base_type::iterator to_base_type_iterator(iterator value) noexcept {
1422 return ilist<type_t>::to_iterator(value, *this, data_->items);
1423 }
1424
1425 const_iterator to_type_iterator(typename base_type::const_iterator value) const noexcept {
1426 return ilist<type_t>::to_iterator(value, data_->items, *this);
1427 }
1428
1429 iterator to_type_iterator(typename base_type::iterator value) noexcept {
1430 return ilist<type_t>::to_iterator(value, data_->items, *this);
1431 }
1432
1433 struct list_data {
1434 list_data() = default;
1435 explicit list_data(const allocator_type& alloc) noexcept : items(alloc) {}
1436 list_data(size_type count, const type_t& value, const allocator_type& alloc = allocator_type()) : items(count, value, alloc) {}
1437 explicit list_data(size_type count, const allocator_type& alloc = allocator_type()) : items(count, alloc) {}
1438 template<class input_iterator_t>
1439 list_data(input_iterator_t first, input_iterator_t last, const allocator_type& alloc = allocator_type()) : items(first, last, alloc) {}
1440 list_data(const xtd::collections::generic::ienumerable<type_t>& collection, const allocator_type& alloc = allocator_type()) : items(collection.begin(), collection.end(), alloc) {}
1441 list_data(const list& list) : items(list.data_->items), version(list.data_->version) {}
1442 list_data(const base_type& list) : items(list) {}
1443 list_data(const list& list, const allocator_type& alloc) : items(list.data_->items, alloc), version(list.data_->version) {}
1444 list_data(const base_type& list, const allocator_type& alloc) : items(list, alloc) {}
1445 list_data(std::initializer_list<type_t> items, const allocator_type& alloc = allocator_type()) : items(items.begin(), items.end(), alloc) {}
1446 list_data(list&& other) : items(std::move(other.data_->items)), version(std::move(other.data_->version)) {other.data_->items.clear(); other.data_->version = 0;}
1447 list_data(base_type&& other) : items(std::move(other)) {other.clear();}
1448 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;}
1449 list_data(base_type&& other, const allocator_type& alloc) : items(std::move(other), alloc) {}
1450
1451 list_data(const list_data&) = default;
1452 list_data& operator =(const list_data&) = default;
1453
1454 base_type items;
1455 size_type version = 0;
1456 xtd::object sync_root;
1457 };
1458
1459 xtd::ptr<list_data> data_ = xtd::new_ptr<list_data>();
1460 };
1461
1463 // C++17 deduction guides for xtd::collections::generic::list
1464 // {
1465 template<class type_t>
1466 list(std::initializer_list<type_t>) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1467
1468 template<class type_t>
1469 list(const ienumerable<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1470
1471 template<class type_t>
1472 list(const ilist<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1473
1474 template<class type_t>
1475 list(const std::vector<type_t>&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1476
1477 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1478 list(const list<type_t, allocator_t>&) -> list<type_t, allocator_t>;
1479
1480 template<class type_t>
1481 list(std::vector<type_t>&&) -> list<type_t, helpers::allocator<type_to_list_t<type_t>>>;
1482
1483 template<class type_t, class allocator_t = helpers::allocator<type_to_list_t<type_t>>>
1484 list(list<type_t, allocator_t>&&) -> list<type_t, allocator_t>;
1485 // }
1487 }
1488 }
1489}
1490
1493 template <class enumerable_t, class source_t>
1495 return xtd::linq::enumerable::to_list(base());
1496 }
1497}
1498
1499namespace xtd::linq {
1500 template <class source_t>
1502 static thread_local auto result = xtd::collections::generic::list<source_t> {};
1504 return result;
1505 }
1506}
1508
Contains xtd::collections::generic::helpers::allocator alias.
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
static basic_string join(const basic_string separator, const collection_t &values) noexcept
Concatenates a specified separator basic_string between each element of a specified object array,...
Definition basic_string.hpp:2288
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 target_collection_t::const_iterator to_iterator(typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept
Converts source iterator to target iterator.
Definition enumerable_iterators.hpp:188
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< type_t, xtd::collections::generic::ienumerable< type_t > >::iterator iterator
Represents the iterator of xtd::collections::generic::ienumerable value type.
Definition ienumerable.hpp:44
typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::const_iterator const_iterator
Represents the const iterator of xtd::collections::generic::ienumerable value type.
Definition ienumerable.hpp:46
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
Represents a collection of objects that can be individually accessed by index.
Definition ilist.hpp:41
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:1018
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
virtual void swap(list &other) noexcept
Exchanges the contents and capacity of the container with those of other. Does not invoke any move,...
Definition list.hpp:1315
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 void push_back(type_t &&value)
Appends the given element value to the end of the container.
Definition list.hpp:1127
virtual reference at(size_type index)
Returns a reference to the element at specified location pos, with bounds checking.
Definition list.hpp:543
list get_range(size_type index, size_type count)
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.hpp:923
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:551
list< type_t > slice(size_type start, size_type length) const
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.hpp:1259
type_t find_last(xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:844
xtd::size find_index(xtd::size start_index, xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:817
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:569
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:582
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.hpp:720
xtd::size find_last_index(xtd::size start_index, xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:863
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< type_t >::iterator iterator
Represents the iterator of list value type.
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:677
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:637
bool exists(xtd::predicate< const type_t & > match) const
Determines whether the xtd::collections::generic::list <type_t> contains elements that match the cond...
Definition list.hpp:763
const value_type * const_pointer
Represents the const pointer of list value type.
Definition list.hpp:143
const base_type const_base_type
Represents the list 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
virtual void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.hpp:1353
virtual xtd::array< value_type > to_array() const noexcept
Copies the elements of the xtd::collections::generic::list <type_t> to a new array.
Definition list.hpp:1327
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
void reverse()
Reverses the order of the elements in the entire xtd::collections::generic::list <type_t>.
Definition list.hpp:1226
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:1032
void sort(xtd::size index, xtd::size count, const xtd::collections::generic::icomparer< type_t > &comparer)
Sorts the elements in a range of elements in xtd::collections::generic::list <type_t> using the speci...
Definition list.hpp:1303
void remove_at(size_type index) override
Removes the element at the specified index of the xtd::collections::generic::list <type_t>.
Definition list.hpp:1175
void assign(size_type count, const type_t &value)
Replaces the contents with count copies of value value.
Definition list.hpp:516
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_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.hpp:1401
const_iterator cbegin() const noexcept override
Returns an iterator to the first element of the enumarable.
Definition list.hpp:313
virtual void pop_back()
Removes the last element of the container.
Definition list.hpp:1110
void for_each(xtd::action< const type_t & > action)
Performs the specified action on each element of the xtd::collections::generic::list <type_t>.
Definition list.hpp:888
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:526
typename base_type::reverse_iterator reverse_iterator
Represents the reverse iterator of list value type.
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:662
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:654
size_type last_index_of(const type_t &value, size_type index, size_type count) const
Determines the last index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:1097
xtd::size find_index(xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:809
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< type_t >::const_iterator const_iterator
Represents the const iterator of list value type.
Definition list.hpp:147
list< type_t > find_all(xtd::predicate< const type_t & > match) const
Retrieves all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:797
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:615
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
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.hpp:1331
virtual const_reference front() const
Returns a reference to the first element in the container.
Definition list.hpp:379
void sort(const xtd::collections::generic::icomparer< type_t > &comparer)
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified compare...
Definition list.hpp:1291
bool equals(const list &rhs) const noexcept override
Indicates whether the current object is equal to another object of the same type.
Definition list.hpp:721
virtual base_type & get_base_type() noexcept
Returns the underlying base type.
Definition list.hpp:900
size_type index_of(const type_t &value) const noexcept override
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:932
size_type last_index_of(const type_t &value, size_type index) const
Determines the last index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:1088
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:707
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:1078
typename xtd::collections::generic::helpers::allocator< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type > allocator_type
Represents the list allocator type.
Definition list.hpp: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
Represents the list difference type (usually xtd::ptrdiff).
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:598
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
virtual void shrink_to_fit()
Requests the removal of unused capacity.
Definition list.hpp:1252
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
Represents the list size type (usually xtd::size).
Definition list.hpp:133
const value_type & const_reference
Represents the const reference of list value type.
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
xtd::size find_last_index(xtd::size start_index, xtd::size count, xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:872
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:533
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:715
std::vector< typename std::conditional< std::is_same< bool, value_type >::value, xtd::byte, value_type >::type, allocator_type > base_type
Represents the list base type.
Definition list.hpp: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
void reverse(size_type index, size_type count)
Reverses the order of the elements in the specified range.
Definition list.hpp:1236
virtual allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition list.hpp:895
void sort(xtd::comparison< const type_t & > comparison)
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified xtd::co...
Definition list.hpp:1280
virtual void remove_range(size_type index, size_type count)
Removes a range of elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:1190
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp:340
virtual void reserve(size_type new_cap)
Increase the capacity of the vector (the total number of elements that the vector can hold without re...
Definition list.hpp:1201
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
xtd::size find_index(xtd::size start_index, xtd::size count, xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:826
list & operator=(const list &other)=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
typename base_type::const_reverse_iterator const_reverse_iterator
Represents the const reverse iterator of list value type.
Definition list.hpp: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
Represents the reference of list value type.
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:1054
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::list <type_t>.
Definition list.hpp:907
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:490
virtual void resize(size_type count, const value_type &value)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.hpp:1213
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:511
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
xtd::size remove_all(const xtd::predicate< const type_t & > &match)
Removes all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:1158
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:965
virtual void resize(size_type count)
Resizes the container to contain count elements, does nothing if count == size(). @param count The ne...
Definition list.hpp:1207
xtd::size find_last_index(xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:855
virtual size_type index_of(const type_t &value, size_type index) const
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:942
void sort()
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.
Definition list.hpp:1273
bool true_for_all(xtd::predicate< const type_t & > match) const
Determines whether every element in the xtd::collections::generic::list <type_t> matches the conditio...
Definition list.hpp:1366
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:500
value_type * pointer
Represents the pointer of list value type.
Definition list.hpp:141
virtual iterator erase(const_iterator first, const_iterator last)
Erases the specified elements from the container.
Definition list.hpp:747
virtual void push_back(const type_t &value)
Appends the given element value to the end of the container.
Definition list.hpp:1119
virtual const base_type & get_base_type() const noexcept
Returns the underlying base type.
Definition list.hpp:903
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:1008
virtual iterator erase(const_iterator pos)
Erases the specified elements from the container.
Definition list.hpp:735
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:623
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
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:950
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:998
iterator emplace(const_iterator pos, args_t &&... args)
Inserts a new element into the container directly before pos.
Definition list.hpp:697
type_t find(xtd::predicate< const type_t & > match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:780
bool remove(const type_t &item) override
Removes the first occurrence of a specific object from the xtd::collections::generic::list <type_t>.
Definition list.hpp:1137
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:986
virtual iterator insert(const_iterator pos, const type_t &&value)
Inserts elements at the specified location in the container.
Definition list.hpp:975
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:43
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::helpers::comparer struct.
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
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
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
std::allocator< type_t > allocator
Represent an allocator alias.
Definition allocator.hpp:38
@ argument
The argument is not valid.
@ index_out_of_range
The index is out of range.
@ argument_out_of_range
The argument is out of range.
@ invalid_operation
The operation is not valid.
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
std::type_info type
Stores information about a type.
Definition type.hpp:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
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
@ other
The operating system is other.
@ c
The C key.
@ i
The I key.
@ insert
The INS (INSERT) key.
Contains xtd::collections::ilist alias.
The xtd::extensions namespace contains interface extensions.
Definition collection_operators.hpp:13
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 xtd_about_box.hpp:10
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Implements a function object for performing comparisons. Unless specialised, invokes operator== on ty...
Definition equator.hpp:38