9#define __XTD_CORE_INTERNAL__
12#undef __XTD_CORE_INTERNAL__
78 template<
class type_t,
class allocator_t>
79 class list :
public xtd::object,
public xtd::collections::generic::ilist<type_t>,
public xtd::iequatable<xtd::collections::generic::list<type_t, allocator_t >> {
82 bool operator()(
const type_t& e1,
const type_t& e2)
const {
return comparer_.compare(e1, e2) < 0;}
86 struct __comparison_comparer__ {
88 bool operator()(
const type_t& e1,
const type_t& e2)
const {
return comparison_(e1, e2) < 0;}
92 struct __enumerator__ :
public ienumerator<type_t> {
96 const type_t& current()
const override {
98 if (index_ < items_.
count())
return items_[index_];
99 return default_value_;
102 bool move_next()
override {
104 return ++index_ < items_.
count();
107 void reset()
override {
108 version_ = items_.data_->items.version();
116 type_t default_value_;
126 using base_type =
typename __xtd_raw_array_data__<value_type>::base_type;
176 data_ = std::move(
list.data_);
192 template <std::input_iterator input_iterator_t>
194 for (
auto iterator =
first; iterator !=
last; ++iterator)
252 if (value <
capacity()) data_->items.shrink_to_fit();
253 data_->items.reserve(value);
290 const auto&
items() const noexcept {
return data_->items;}
293 auto&
items() noexcept {
return data_->items;}
312 void add(
const type_t& item)
override {data_->items.push_back(item);}
326 void add(type_t&& item) {data_->items.push_back(std::move(item));}
349 template<
class enumerable_t>
350 void add_range(
const enumerable_t& enumerable) {insert_range(
count(), enumerable);}
401 auto first = data_->items.begin();
402 auto last = data_->items.begin();
403 std::advance(
first, index);
407 if (position != data_->items.end() && !
comparer.
compare(item, *position))
408 return std::distance(data_->items.begin(), position);
409 return ~std::distance(data_->items.begin(), position);
416 void clear()
override {data_->items.clear();}
421 bool contains(
const type_t& value)
const noexcept override {
432 template<
class output_t,
class converter_t>
436 for (
const auto& item :
self_)
437 result.add(apply_converter(item));
477 for (
const type_t& item :
self_) {
478 if (
i >= index +
count)
return;
480 array[array_index +
c] = item;
493 return self_.capacity();
507 if (
count() != obj.count())
return false;
524 template<
class predicate_t>
540 template<
class predicate_t>
558 template<
class predicate_t>
561 auto result =
list {};
562 for (
const auto& item :
self_)
572 template<
class predicate_t>
581 template<
class predicate_t>
591 template<
class predicate_t>
595 for (
auto index = start_index; index < start_index +
count; ++index)
611 template<
class predicate_t>
623 template<
class predicate_t>
632 template<
class predicate_t>
642 template<
class predicate_t>
646 auto end_index = start_index + 1 -
count;
647 for (
auto index = start_index; ; --index) {
649 if (index == end_index)
break;
662 template<
class action_t>
665 for (
const auto& item :
self_)
689 return list<type_t> {data_->items.begin() + index, data_->items.begin() + index +
count};
722 data_->items.insert(data_->items.begin() + index, value);
731 data_->items.insert(data_->items.begin() + index, std::move(value));
743 void insert_range(
size_type index,
const xtd::collections::generic::ienumerable<type_t>& enumerable) {
747 if (
static_cast<const void*
>(&enumerable) ==
static_cast<const void*
>(
this)) {
748 insert_range(index,
list(enumerable));
752 data_->items.insert(data_->items.begin() + index, enumerable.
begin(), enumerable.
end());
763 void insert_range(
size_type index,
const std::initializer_list<type_t>&
items) {
765 data_->items.insert(data_->items.begin() + index,
items.begin(),
items.end());
769 template<
class collection_t>
774 if (
static_cast<const void*
>(&
items) ==
static_cast<const void*
>(
this)) {
779 data_->items.insert(data_->items.begin() + index,
items.begin(),
items.end());
813 bool remove(
const type_t& item)
noexcept override {
815 if (index ==
npos)
return false;
831 template<
class predicate_t>
835 auto iterator = data_->items.begin();
836 while (iterator != data_->items.end())
839 iterator = data_->items.erase(iterator);
850 data_->items.erase(data_->items.begin() + index);
863 data_->items.erase(data_->items.begin() + index, data_->items.begin() + index +
count);
881 data_->items.resize(
count, value);
902 data_->items.increment_version();
903 std::reverse(data_->items.begin() + index, data_->items.begin() + index +
count);
913 return list<type_t> {data_->items.begin() + start, data_->items.begin() + start +
length};
933 data_->
items.increment_version();
934 std::sort(data_->items.begin(), data_->items.end(), __comparison_comparer__ {comparison});
957 data_->items.increment_version();
958 std::sort(data_->items.begin() + index, data_->items.begin() + index +
count, __comparer__ {comparer});
973 string to_string() const noexcept
override {
return xtd::string::format(
"[{}]", xtd::string::join(
", ",
self_));}
1008 template<
class prediacate_t>
1011 for (
const auto& item :
self_)
1028 data_->items = std::move(
other.data_->items);
1045 return data_->items[index];
1053 return data_->items[index];
1065 bool is_fixed_size() const noexcept
override {
return false;}
1066 bool is_read_only() const noexcept
override {
return false;}
1067 bool is_synchronized() const noexcept
override {
return false;}
1068 const xtd::object& sync_root() const noexcept
override {
return data_->sync_root;}
1071 __xtd_raw_array_data__<value_type> items;
1072 xtd::object sync_root;
1081 template<
class type_t>
1084 template<
class type_t>
1087 template<
class type_t>
1090 template<
class type_t>
1093 template<
class type_t,
class allocator_t = helpers::allocator<type_t>>
1096 template<
class type_t>
1099 template<
class type_t,
class allocator_t = helpers::allocator<type_t>>
1109 template <
class enumerable_t,
class source_t>
1116 template <
class source_t>
1117 inline auto enumerable::to_list(
const xtd::collections::generic::ienumerable<source_t>& source)
noexcept {
1118 auto result = xtd::collections::generic::list<source_t> {};
1119 result = xtd::collections::generic::list<source_t> {source};
Contains xtd::collections::generic::list definitions.
Contains xtd_raw_array_data class.
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:63
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 begin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:141
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:156
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: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:79
xtd::size find_last_index(xtd::size start_index, predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:633
list< type_t > & sort()
Sorts the elements in the entire xtd::collections::generic::list <type_t> using the default comparer.
Definition list.hpp:925
void add(const type_t &item) override
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:312
xtd::size binary_search(const type_t &item, const xtd::collections::generic::icomparer< type_t > &comparer) const noexcept
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the specifie...
Definition list.hpp:384
list< type_t > & 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:943
xtd::size binary_search(const type_t &item) const noexcept
Searches the entire sorted xtd::collections::generic::list <type_t> for an element using the default ...
Definition list.hpp:372
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:687
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:911
list< type_t > & 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:955
list(base_type &&list)
Move constructor with specified base type list.
Definition list.hpp:184
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition list.hpp:502
void for_each(action_t action)
Performs the specified action on each element of the xtd::collections::generic::list <type_t>.
Definition list.hpp:663
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:861
void capacity(size_type value)
Sets the total number of elements the internal data structure can hold without resizing.
Definition list.hpp:248
list find_all(predicate_t match) const
Retrieves all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:559
const value_type * const_pointer
Definition list.hpp:138
const base_type const_base_type
Definition list.hpp:128
bool remove(const type_t &item) noexcept override
Removes the first occurrence of a specific object from the xtd::collections::generic::list <type_t>.
Definition list.hpp:813
xtd::size find_last_index(predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:624
bool true_for_all(prediacate_t match) const
Determines whether every element in the xtd::collections::generic::list <type_t> matches the conditio...
Definition list.hpp:1009
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:969
void reverse()
Reverses the order of the elements in the entire xtd::collections::generic::list <type_t>.
Definition list.hpp:890
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:848
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:474
const_reference operator[](size_type index) const override
Returns a reference to the element at specified location index.
Definition list.hpp:1043
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:459
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:804
void clear() override
Removes all elements from the xtd::collections::generic::list <type_t>.
Definition list.hpp:416
string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition list.hpp:973
xtd::size find_last_index(xtd::size start_index, xtd::size count, predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:643
list(std::initializer_list< type_t > items)
Constructs the container with the contents of the specified initializer list, and allocator.
Definition list.hpp:187
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:695
size_type last_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:795
list(const list &list)
Default copy constructor with specified list.
Definition list.hpp:172
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:399
list() noexcept=default
Initializes a new instance of the xtd::collections::generic::list class that is empty.
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:451
auto & items() noexcept
Returns the underlying base type items.
Definition list.hpp:293
xtd::size size_type
Definition list.hpp:130
xtd::size find_index(predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:573
const value_type & const_reference
Definition list.hpp:134
list< type_t > & 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:932
xtd::size find_index(xtd::size start_index, predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:582
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:491
bool equals(const list &obj) const noexcept override
Indicates whether the current object is equal to another object of the same type.
Definition list.hpp:506
void reverse(size_type index, size_type count)
Reverses the order of the elements in the specified range.
Definition list.hpp:900
size_type count() const noexcept override
Gets the number of elements contained in the xtd::collections::generic::list <type_t>.
Definition list.hpp:277
typename ilist< xtd::any_object >::value_type value_type
Definition list.hpp:124
list(list &&list)
Move constructor with specified list.
Definition list.hpp:175
list & operator=(const list &other)=default
Copy assignment operator. Replaces the contents with a copy of the contents of other.
list(input_iterator_t first, input_iterator_t last)
Constructs the container with the contents of the range [first, last).
Definition list.hpp:193
value_type & reference
Definition list.hpp:132
enumerator< value_type > get_enumerator() const noexcept override
Returns an enumerator that iterates through the xtd::collections::generic::list <type_t>.
Definition list.hpp:671
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:336
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 ...
Definition list.hpp:878
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:357
void add(type_t &&item)
Adds an object to the end of the xtd::collections::generic::list <type_t>.
Definition list.hpp:326
typename __xtd_raw_array_data__< value_type >::base_type base_type
Definition list.hpp:126
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:169
xtd::size remove_all(predicate_t match)
Removes all the elements that match the conditions defined by the specified predicate.
Definition list.hpp:832
xtd::size find_index(xtd::size start_index, xtd::size count, predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:592
void trim_excess()
Sets the capacity to the actual number of elements in the xtd::collections::generic::list <type_t>,...
Definition list.hpp:995
list< output_t > convert_all(converter_t converter) const
Converts the elements in the current xtd::colllections::generic::list <type_t> to another type,...
Definition list.hpp:433
pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:282
list(const base_type &list)
Copy constructor with specified base type list.
Definition list.hpp:181
bool exists(predicate_t match) const
Determines whether the xtd::collections::generic::list <type_t> contains elements that match the cond...
Definition list.hpp:525
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:346
value_type * pointer
Definition list.hpp:136
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:704
const auto & items() const noexcept
Returns the underlying base type items.
Definition list.hpp:290
optional< type_t > find_last(predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:612
xtd::collections::object_model::read_only_collection< value_type > read_only_collection
Definition list.hpp:140
const_pointer data() const noexcept
Returns pointer to the underlying array serving as element storage.
Definition list.hpp:286
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:421
size_type capacity() const noexcept
Definition list.hpp:224
optional< type_t > find(predicate_t match) const
Searches for an element that matches the conditions defined by the specified predicate,...
Definition list.hpp:541
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:38
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
static auto to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.hpp:114
Contains xtd::comparison delegate.
Contains xtd::converter alias.
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::comparer <type_t> class.
Contains xtd::collections::generic::ilist <type_t> interface.
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
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:59
@ out_of_memory
Out of memory.
Definition exception_case.hpp:85
@ 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
#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:900
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:25
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:58
@ add
The Add key.
Definition console_key.hpp:170
@ c
The C key.
Definition console_key.hpp:92
@ n
The N key.
Definition console_key.hpp:114
@ i
The I key.
Definition console_key.hpp:104
@ insert
The INS (INSERT) key.
Definition console_key.hpp:62
Contains xtd::intptr type.
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:45
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::object_model::read_only_collection class.
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:38