xtd 0.2.0
Loading...
Searching...
No Matches
list.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "helpers/equator.hpp"
7#include "helpers/lesser.hpp"
9#include "comparer.hpp"
10#include "ilist.hpp"
11#define __XTD_CORE_INTERNAL__
13#undef __XTD_CORE_INTERNAL__
15#include "../../action.hpp"
16#include "../../comparison.hpp"
17#include "../../converter.hpp"
18#include "../../intptr.hpp"
19#include "../../is.hpp"
20#include "../../object.hpp"
21#include "../../optional.hpp"
22#include "../../new_ptr.hpp"
23#include "../../predicate.hpp"
24#include "../../self.hpp"
25#include "../../string.hpp"
26
28namespace xtd {
30 namespace collections {
32 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 public:
83
86 using value_type = typename ilist<type_t>::value_type;
100 using const_pointer = const value_type*;
104
106
116 list() noexcept = default;
123 explicit list(size_type capacity) {self_.capacity(capacity);}
134 list(const list& list) {*data_ = *list.data_;}
138 data_ = std::move(list.data_);
139 list.data_ = new_ptr<list_data>();
140 }
141
143 list(const base_type& list) {data_->items = list;}
146 list(base_type&& list) {data_->items = std::move(list);}
149 list(std::initializer_list<type_t> items) {add_range(items);}
153 template <std::input_iterator input_iterator_t>
154 list(input_iterator_t first, input_iterator_t last) {
155 for (auto iterator = first; iterator != last; ++iterator)
156 add(*iterator);
157 }
158
159
161
185 auto capacity() const noexcept -> size_type {return data_->items.capacity();}
209 auto capacity(size_type value) -> void {
212 if (value == capacity()) return;
213 if (value < capacity()) data_->items.shrink_to_fit();
214 data_->items.reserve(value);
215 }
216
238 auto count() const noexcept -> size_type override {return data_->items.size();}
239
243 auto data() noexcept -> pointer {return reinterpret_cast<pointer>(data_->items.data());}
247 auto data() const noexcept -> const_pointer {return reinterpret_cast<const_pointer>(data_->items.data());}
248
251 const auto& items() const noexcept {return data_->items;}
254 auto& items() noexcept {return data_->items;}
256
258
273 auto add(const type_t& item) -> void override {data_->items.push_back(item);}
287 auto add(type_t&& item) -> void {data_->items.push_back(std::move(item));}
288
297 auto add_range(const xtd::collections::generic::ienumerable<type_t>& enumerable) -> void {insert_range(count(), enumerable);}
298
307 auto add_range(std::initializer_list<type_t> il) -> void {insert_range(count(), il);}
308
310 template<class enumerable_t>
311 auto add_range(const enumerable_t& enumerable) -> void {insert_range(count(), enumerable);}
313
318 auto as_read_only() const noexcept -> read_only_collection {return read_only_collection {self_};}
319
333 auto binary_search(const type_t& item) const noexcept -> xtd::size {return binary_search(0, count(), item, xtd::collections::generic::comparer<type_t>::default_comparer);}
345 auto binary_search(const type_t& item, const xtd::collections::generic::icomparer<type_t>& comparer) const noexcept -> xtd::size {return binary_search(0, count(), item, comparer);}
362 auto first = data_->items.begin();
363 auto last = data_->items.begin();
364 std::advance(first, index);
365 std::advance(last, index + count);
366 auto position = std::lower_bound(first, last, item, helpers::lesser<type_t> {comparer});
367
368 if (position != data_->items.end() && !comparer.compare(item, *position))
369 return std::distance(data_->items.begin(), position);
370 return ~std::distance(data_->items.begin(), position);
371 }
372
377 auto clear() -> void override {data_->items.clear();}
378
382 auto contains(const type_t& value) const noexcept -> bool override {
383 return index_of(value) != npos;
384 }
385
393 template<class output_t, class converter_t>
394 auto convert_all(converter_t converter) const -> list<output_t> {
395 auto result = list<output_t> {};
396 auto apply_converter = xtd::converter<output_t, const type_t&> {converter};
397 for (const auto& item : self_)
398 result.add(apply_converter(item));
399 return result;
400 }
401
411 auto copy_to(xtd::array<type_t>& array) const -> void {copy_to(0, array, 0, count());}
419 auto copy_to(xtd::array<type_t>& array, size_type array_index) const -> void override {copy_to(0, array, array_index, count());}
433 auto copy_to(size_type index, xtd::array<type_t>& array, size_type array_index, size_type count) const -> void {
435 for (auto i = index; i < (index + count); ++i)
436 array[array_index++] = self_[i];
437 }
438
444 data_->items.reserve(capacity);
445 return self_.capacity();
446 }
447
454 auto equals(const object& obj) const noexcept -> bool override {return is<list<value_type>>(obj) && equals(static_cast<const list<value_type>& > (obj));}
458 auto equals(const list& obj) const noexcept -> bool override {
459 if (count() != obj.count()) return false;
460 for (size_type i = 0; i < count(); i++)
461 if (!helpers::equator<type_t> {}(self_[i], obj[i])) return false;
462 return true;
463 }
464
476 template<class predicate_t>
477 auto exists(predicate_t match) const -> bool {
478 return find_index(match) != npos;
479 }
480
492 template<class predicate_t>
493 auto find(predicate_t match) const -> optional<type_t> {
494 auto index = find_index(match);
495 if (index == npos) return nullopt;
496 return self_[index];
497 }
498
510 template<class predicate_t>
511 auto find_all(predicate_t match) const -> list {
513 auto result = list {};
514 for (const auto& item : self_)
515 if (predicate(item)) result.add(item);
516 return result;
517 }
518
524 template<class predicate_t>
525 auto find_index(predicate_t match) const -> xtd::size {return find_index(0, count(), match);}
533 template<class predicate_t>
534 auto find_index(xtd::size start_index, predicate_t match) const -> xtd::size {return find_index(start_index, count() - start_index, match);}
543 template<class predicate_t>
544 auto find_index(xtd::size start_index, xtd::size count, predicate_t match) const -> xtd::size {
547 for (auto index = start_index; index < start_index + count; ++index)
548 if (predicate(self_[index])) return index;
549 return npos;
550 }
551
563 template<class predicate_t>
564 auto find_last(predicate_t match) const -> optional<type_t> {
565 auto index = find_last_index(match);
566 if (index == npos) return nullopt;
567 return self_[index];
568 }
569
575 template<class predicate_t>
576 auto find_last_index(predicate_t match) const -> xtd::size {return find_last_index(count() - 1, count(), match);}
584 template<class predicate_t>
585 auto find_last_index(xtd::size start_index, predicate_t match) const -> xtd::size {return find_last_index(start_index, start_index + 1, match);}
594 template<class predicate_t>
595 auto find_last_index(xtd::size start_index, xtd::size count, predicate_t match) const -> xtd::size {
598 auto end_index = start_index + 1 - count;
599 for (auto index = start_index; ; --index) {
600 if (predicate(self_[index])) return index;
601 if (index == end_index) break;
602 }
603 return npos;
604 }
605
614 template<class action_t>
615 auto for_each(action_t action) -> void {
616 auto apply_action = xtd::action<const type_t&> {action};
617 for (const auto& item : self_)
618 apply_action(item);
619 }
620
623 enumerator<value_type> get_enumerator() const noexcept override {
624 struct list_enumerator : public ienumerator<value_type> {
625 explicit list_enumerator(const list& items, xtd::size version) : items_(items), version_(version) {}
626
627 const value_type& current() const override {
629 if (version_ != items_.data_->items.version()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
630 return items_[index_];
631 }
632
633 bool move_next() override {
634 if (version_ != items_.data_->items.version()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
635 return ++index_ < items_.count();
636 }
637
638 void reset() override {
639 version_ = items_.data_->items.version();
640 index_ = list::npos;
641 }
642
643 private:
644 size_type index_ = list::npos;
645 const list& items_;
646 size_type version_ = 0;
647 };
648
649 return {new_ptr<list_enumerator>(self_, data_->items.version())};
650 }
651
666 return list<type_t> {data_->items.begin() + index, data_->items.begin() + index + count};
667 }
668
672 auto index_of(const type_t& value) const noexcept -> size_type override {
673 if (count() == 0) return npos;
674 return index_of(value, 0, count());
675 }
676
681 auto index_of(const type_t& value, size_type index) const -> size_type {return index_of(value, index, count() - index);}
688 auto index_of(const type_t& value, size_type index, size_type count) const -> size_type {
689 return find_index(index, count, delegate_(auto n) {return helpers::equator<type_t> {}(n, value);});
690 }
691
697 auto insert(size_type index, const type_t& value) -> void override {
699 data_->items.insert(data_->items.begin() + index, value);
700 }
706 auto insert(size_type index, type_t&& value) -> void {
708 data_->items.insert(data_->items.begin() + index, std::move(value));
709 }
710
720 auto insert_range(size_type index, const xtd::collections::generic::ienumerable<type_t>& enumerable) -> void {
722
723 // If the collection is this instance, it must be copied to avoid an infinite loop.
724 if (static_cast<const void*>(&enumerable) == static_cast<const void*>(this)) {
725 insert_range(index, list(enumerable));
726 return;
727 }
728
729 data_->items.insert(data_->items.begin() + index, enumerable.begin(), enumerable.end());
730 }
740 auto insert_range(size_type index, const std::initializer_list<type_t>& items) -> void {
742 data_->items.insert(data_->items.begin() + index, items.begin(), items.end());
743 }
744
746 template<class collection_t>
747 auto insert_range(size_type index, const collection_t& items) -> void {
749
750 // If the collection is this instance, it must be copied to avoid an infinite loop.
751 if (static_cast<const void*>(&items) == static_cast<const void*>(this)) {
752 insert_range(index, list(items));
753 return;
754 }
755
756 data_->items.insert(data_->items.begin() + index, items.begin(), items.end());
757 }
759
763 auto last_index_of(const type_t& value) const noexcept -> size_type {
764 if (count() == 0) return npos;
765 return last_index_of(value, count() - 1, count());
766 }
772 auto last_index_of(const type_t& value, size_type index) const -> size_type {
773 return last_index_of(value, index, index + 1);
774 }
775
781 auto last_index_of(const type_t& value, size_type index, size_type count) const -> size_type {
782 return find_last_index(index, count, delegate_(auto n) {return helpers::equator<type_t> {}(n, value);});
783 }
784
790 auto remove(const type_t& item) noexcept -> bool override {
791 auto index = index_of(item);
792 if (index == npos) return false;
793 remove_at(index);
794 return true;
795 }
796
808 template<class predicate_t>
809 auto remove_all(predicate_t match) -> xtd::size {
811 auto count = xtd::size {0};
812 auto iterator = data_->items.begin();
813 while (iterator != data_->items.end())
814 if (!predicate(*iterator)) iterator++;
815 else {
816 iterator = data_->items.erase(iterator);
817 ++count;
818 }
819 return count;
820 }
821
825 auto remove_at(size_type index) -> void override {
827 data_->items.erase(data_->items.begin() + index);
828 }
829
838 auto remove_range(size_type index, size_type count) -> void {
840 data_->items.erase(data_->items.begin() + index, data_->items.begin() + index + count);
841 }
842
848 virtual auto resize(size_type count) -> void {resize(count, value_type {});}
855 virtual auto resize(size_type count, const value_type& value) -> void {
857 if (count == self_.count()) return;
858 data_->items.resize(count, value);
859 }
860
867 auto reverse() -> list<type_t>& {return reverse(0, count());}
879 data_->items.increment_version();
880 std::reverse(data_->items.begin() + index, data_->items.begin() + index + count);
881 return self_;
882 }
883
891 return list<type_t> {data_->items.begin() + start, data_->items.begin() + start + length};
892 }
893
904
911 data_->items.increment_version();
912 std::sort(data_->items.begin(), data_->items.end(), [&](const type_t& x, const type_t& y) {return comparison(x, y) < 0;});
913 return self_;
914 }
915
924
935 data_->items.increment_version();
936 std::sort(data_->items.begin() + index, data_->items.begin() + index + count, helpers::lesser<type_t> {comparer});
937 return self_;
938 }
939
947 auto to_array() const noexcept -> xtd::array<value_type> {return count() ? xtd::array<value_type>(data_->items.begin(), data_->items.end()) : xtd::array<value_type> {};}
948
951 auto to_string() const noexcept -> xtd::string override {return xtd::string::format("[{}]", xtd::string::join(", ", self_));}
952
973 auto trim_excess() -> void {data_->items.shrink_to_fit();}
974
986 template<class prediacate_t>
987 auto true_for_all(prediacate_t match) const -> bool {
989 for (const auto& item : self_)
990 if (!predicate(item)) return false;
991 return true;
992 }
993
994
996
1001 auto operator =(const list& other) -> list& = default;
1005 auto operator =(list&& other) noexcept -> list& {
1006 data_->items = std::move(other.data_->items);
1007 return self_;
1008 }
1009
1012 auto operator =(const std::initializer_list<type_t>& items) -> list& {
1013 data_->items = items;
1014 return self_;
1015 }
1016
1021 auto operator [](size_type index) const -> const_reference override {
1023 return data_->items[index];
1024 }
1025
1029 auto operator [](size_type index) -> reference override {
1031 return data_->items[index];
1032 }
1033
1036 operator const_base_type& () const noexcept {return data_->items;}
1039 operator base_type& () noexcept {return data_->items;}
1041
1042 private:
1043 auto is_fixed_size() const noexcept -> bool override {return false;}
1044 auto is_read_only() const noexcept -> bool override {return false;}
1045 auto is_synchronized() const noexcept -> bool override {return false;}
1046 const xtd::object& sync_root() const noexcept override {return data_->sync_root;}
1047
1048 struct list_data {
1049 xtd::collections::generic::helpers::raw_array<value_type, allocator_t> items;
1050 xtd::object sync_root;
1051 };
1052
1054 };
1055
1057 // Deduction guides for xtd::collections::generic::list
1058 // {
1059 template<class type_t>
1060 list(std::initializer_list<type_t>) -> list<type_t>;
1061
1062 template<class type_t>
1064
1065 template<class type_t>
1066 list(const ilist<type_t>&) -> list<type_t>;
1067
1068 template<class type_t>
1069 list(const std::vector<type_t>&) -> list<type_t>;
1070
1071 template<class type_t, class allocator_t = helpers::allocator<type_t>>
1073
1074 template<class type_t>
1075 list(std::vector<type_t>&&) -> list<type_t>;
1076
1077 template<class type_t, class allocator_t = helpers::allocator<type_t>>
1079
1080 template <class input_iterator_t>
1081 list(input_iterator_t, input_iterator_t) -> list<std::iter_value_t<input_iterator_t>>;
1082 // }
1084 }
1085 }
1086}
1087
1090 template <class enumerable_t, class source_t>
1091 inline auto enumerable<enumerable_t, source_t>::to_list() const noexcept -> xtd::collections::generic::list<source_t> {
1092 return xtd::linq::enumerable::to_list(self());
1093 }
1094}
1095
1096namespace xtd::linq {
1097 template <class source_t>
1098 inline auto enumerable::to_list(const xtd::collections::generic::ienumerable<source_t>& source) noexcept {
1099 auto result = xtd::collections::generic::list<source_t> {};
1100 result = xtd::collections::generic::list<source_t> {source};
1101 return result;
1102 }
1103}
Contains xtd::collections::generic::list definitions.
Contains xtd::action delegate.
Contains xtd::collections::generic::helpers::allocator alias.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual size_type length() const noexcept
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:124
static basic_string join(const basic_string &separator, const collection_t &values) noexcept
Definition basic_string.hpp:1702
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
auto compare(const first_argument_type &x, const second_argument_type &y) const noexcept -> result_type 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
auto to_list() const noexcept -> list< source_t >
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
internal_base_type base_type
Underlying vector type.
Definition raw_array.hpp:123
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:40
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
auto last_index_of(const type_t &value, size_type index, size_type count) const -> size_type
Determines the last index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:781
auto count() const noexcept -> size_type override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp:238
auto index_of(const type_t &value) const noexcept -> size_type override
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:672
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition list.hpp:454
auto find_index(predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:525
auto sort(xtd::comparison< const type_t & > comparison) -> list< type_t > &
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified xtd::co...
Definition list.hpp:910
auto operator[](size_type index) const -> const_reference override
Returns a reference to the element at specified location index.
Definition list.hpp:1021
auto add_range(std::initializer_list< type_t > il) -> void
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.hpp:307
auto sort(xtd::size index, xtd::size count, const xtd::collections::generic::icomparer< type_t > &comparer) -> list< type_t > &
Sorts the elements in a range of elements in xtd::collections::generic::list <type_t> using the speci...
Definition list.hpp:933
list(base_type &&list)
Move constructor with specified base type list.
Definition list.hpp:146
auto sort() -> list< type_t > &
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.
Definition list.hpp:903
const value_type * const_pointer
Definition list.hpp:100
const base_type const_base_type
Definition list.hpp:90
auto remove_range(size_type index, size_type count) -> void
Removes a range of elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:838
auto index_of(const type_t &value, size_type index) const -> size_type
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:681
auto remove(const type_t &item) noexcept -> bool override
Removes the first occurrence of a specific object from the xtd::collections::generic::list <type_t>.
Definition list.hpp:790
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
Definition list.hpp:951
auto add(const type_t &item) -> void override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:273
virtual auto resize(size_type count, const value_type &value) -> void
Resizes the container to contain count elements, does nothing if count == size(). / @param count The ...
Definition list.hpp:855
auto reverse() -> list< type_t > &
Reverses the order of the elements in the entire xtd::collections::generic::list <type_t>.
Definition list.hpp:867
auto binary_search(xtd::size index, xtd::size count, const type_t &item, const xtd::collections::generic::icomparer< type_t > &comparer) const -> xtd::size
Searches a range of elements in the sorted xtd::collections::generic::list <type_t> for an element us...
Definition list.hpp:360
auto find_last(predicate_t match) const -> optional< type_t >
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:564
auto find_index(xtd::size start_index, predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:534
list(std::initializer_list< type_t > items)
Constructs the container with the contents of the specified initializer list, and allocator.
Definition list.hpp:149
auto find_last_index(predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:576
list(const list &list)
Default copy constructor with specified list.
Definition list.hpp:134
auto copy_to(size_type index, xtd::array< type_t > &array, size_type array_index, size_type count) const -> void
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array,...
Definition list.hpp:433
list() noexcept=default
Initializes a new instance of the xtd::collections::generic::list class that is empty.
auto find_last_index(xtd::size start_index, xtd::size count, predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:595
auto & items() noexcept
Returns the underlying base type items.
Definition list.hpp:254
xtd::size size_type
Definition list.hpp:92
auto to_array() const noexcept -> xtd::array< value_type >
Copies the elements of the xtd::collections::generic::list <type_t> to a new array.
Definition list.hpp:947
auto as_read_only() const noexcept -> read_only_collection
Returns a read-only xtd::collections::object_model::read_only_collection <type_t> wrapper for the cur...
Definition list.hpp:318
const value_type & const_reference
Definition list.hpp:96
auto capacity(size_type value) -> void
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:209
auto for_each(action_t action) -> void
Performs the specified action on each element of the xtd::collections::generic::list <type_t>.
Definition list.hpp:615
auto contains(const type_t &value) const noexcept -> bool override
Determines whether an element is in the xtd::colllections::generic::list <type_t>.
Definition list.hpp:382
auto remove_all(predicate_t match) -> xtd::size
Removes all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:809
typename ilist< xtd::any_object >::value_type value_type
Definition list.hpp:86
list(list &&list)
Move constructor with specified list.
Definition list.hpp:137
auto last_index_of(const type_t &value, size_type index) const -> size_type
Determines the index of a specific item in the xtd::collections::generic::list <type_t>.
Definition list.hpp:772
auto exists(predicate_t match) const -> bool
Determines whether the xtd::collections::generic::list <type_t> contains elements that match the cond...
Definition list.hpp:477
auto true_for_all(prediacate_t match) const -> bool
Determines whether every element in the xtd::collections::generic::list <type_t> matches the conditio...
Definition list.hpp:987
list(input_iterator_t first, input_iterator_t last)
Constructs the container with the contents of the range [first, last).
Definition list.hpp:154
value_type & reference
Definition list.hpp:94
auto find_index(xtd::size start_index, xtd::size count, predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:544
auto add_range(const xtd::collections::generic::ienumerable< type_t > &enumerable) -> void
Adds copy of elements from the specified collection to the end of the xtd::collections::generic::list...
Definition list.hpp:297
auto copy_to(xtd::array< type_t > &array, size_type array_index) const -> void override
Copies the entire xtd::colllections::generic::list <type_t> to a compatible one-dimensional array,...
Definition list.hpp:419
auto slice(size_type start, size_type length) const -> list< type_t >
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.hpp:889
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::list <type_t>.
Definition list.hpp:623
auto get_range(size_type index, size_type count) -> list
Creates a shallow copy of a range of elements in the source xtd::collections::generic::list <type_t>.
Definition list.hpp:664
typename xtd::collections::generic::helpers::raw_array< value_type >::base_type base_type
Definition list.hpp:88
list(const xtd::collections::generic::ienumerable< type_t > &collection)
Initializes a new instance of the xtd::collections::generic::list <type_t> class that contains elemen...
Definition list.hpp:131
auto equals(const list &obj) const noexcept -> bool override
Indicates whether the current object is equal to another object of the same type.
Definition list.hpp:458
auto binary_search(const type_t &item, const xtd::collections::generic::icomparer< type_t > &comparer) const noexcept -> xtd::size
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the specifie...
Definition list.hpp:345
auto clear() -> void override
Removes all elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:377
auto binary_search(const type_t &item) const noexcept -> xtd::size
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the default ...
Definition list.hpp:333
auto capacity() const noexcept -> size_type
Definition list.hpp:185
auto data() const noexcept -> const_pointer
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:247
auto remove_at(size_type index) -> void override
Removes the element at the specified index of the xtd::collections::generic::list <type_t>.
Definition list.hpp:825
auto copy_to(xtd::array< type_t > &array) const -> void
Copies the entire xtd::collections::generic::list <type_t> to a compatible one-dimensional array.
Definition list.hpp:411
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.hpp:143
auto ensure_capacity(xtd::size capacity) -> xtd::size
Ensures that the capacity of this list is at least the specified capacity. If the current capacity is...
Definition list.hpp:443
value_type * pointer
Definition list.hpp:98
auto reverse(size_type index, size_type count) -> list< type_t > &
Reverses the order of the elements in the specified range.
Definition list.hpp:877
auto find_all(predicate_t match) const -> list
Retrieves all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:511
const auto & items() const noexcept
Definition list.hpp:251
auto data() noexcept -> pointer
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:243
auto operator=(const list &other) -> list &=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Definition list.hpp:102
auto find(predicate_t match) const -> optional< type_t >
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:493
auto convert_all(converter_t converter) const -> list< output_t >
Converts the elements in the current xtd::colllections::generic::list <type_t> to another type,...
Definition list.hpp:394
auto sort(const xtd::collections::generic::icomparer< type_t > &comparer) -> list< type_t > &
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the specified compare...
Definition list.hpp:921
auto find_last_index(xtd::size start_index, predicate_t match) const -> xtd::size
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:585
auto trim_excess() -> void
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.hpp:973
auto add(type_t &&item) -> void
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:287
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:38
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
static auto to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:115
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.
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
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:61
@ out_of_memory
Out of memory.
Definition exception_case.hpp:87
@ 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:65
#define self_
The self_ expression is a reference value expression whose value is the reference of the implicit obj...
Definition self.hpp:20
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:932
constexpr xtd::size npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:26
constexpr null_opt nullopt
Represents a nullopt value. Used to indicate that an std::optional does not contain a value.
Definition nullopt.hpp:26
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
xtd::func< bool, type_t > predicate
Represents a delegate that defines a set of criteria and determines whether the specified object meet...
Definition predicate.hpp:16
delegate< void(arguments_t...)> action
Represents a xtd::delegate that has variable parameters and does not return a value.
Definition action.hpp:20
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
@ other
The operating system is other.
Definition platform_id.hpp:60
@ add
The Add key.
Definition console_key.hpp:170
@ y
The Y key.
Definition console_key.hpp:136
@ n
The N key.
Definition console_key.hpp:114
@ i
The I key.
Definition console_key.hpp:104
@ x
The X key.
Definition console_key.hpp:134
@ insert
The INS (INSERT) key.
Definition console_key.hpp:62
Contains xtd::intptr type.
Contains xtd::is method.
Contains xtd::collections::generic::helpers::lesser struct.
The xtd::extensions namespace contains interface extensions.
Definition collection_common.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
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:50
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
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
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
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
Contains xtd::new_ptr method.
Contains xtd::object class.
Contains xtd::optional type.
Contains xtd::predicate delegate.
Contains xtd::collections::generic::helpers::raw_array class.
Contains xtd::collections::object_model::read_only_collection class.
Contains self_ keyword.
Contains xtd::string alias.
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:39
Implements a function object for compare data.
Definition lesser.hpp:39