System::Collections::Generic::List class

List class

List forward declaration.

template<typename T>class List : public virtual System::Object,
                                 public System::Collections::Generic::IList<T>
ParameterDescription
TElement type.

Nested classes

Methods

MethodDescription
_add_range(std::initializer_list<T>)C++ specific.
Add(const T&) overrideAdds element to the end of list.
AddInitializer(int, const T)Adds elements to list; used when translating initializers.
AddRange(IEnumerablePtr)Adds all elements from collection (or itself) to the end of current list.
AsReadOnly()Gets read-only reference to this collection.
begin()Gets iterator to the first element of collection.
begin() constGets iterator to the first element of the const-qualified collection.
BinarySearch(const T&) constLooks for item in a sorted list.
BinarySearch(const T&, const SharedPtr<System::Collections::Generic::IComparer<T>>&) constLooks for item in a sorted list.
BinarySearch(int, int, const T&, const SharedPtr<System::Collections::Generic::IComparer<T>>&) constLooks for item in a sorted list.
cbegin() constGets iterator to the first const-qualified element of collection.
cend() constGets iterator for a non-existent const-qualified element behind the end of the collection.
Clear() overrideDeletes all elements.
Contains(const T&) const overrideChecks if item is present in list.
ConvertAll(Converter<T, OutputType>)Creates a list of elements converted to different type.
CopyTo(System::ArrayPtr<T>, int) overrideCopies list elements into existing array elements.
CopyTo(const System::ArrayPtr<T>&)Copies all elements into existing array elements.
CopyTo(int, const System::ArrayPtr<T>&, int, int)Copies elements starting from the specified index into existing array elements.
crbegin() constGets a reverse iterator to the last const-qualified element of collection (first in reverse).
crend() constGets a reverse iterator for a non-existent const-qualified element before the start of the collection.
data()Underlying data structure access function.
data() constUnderlying data structure access function.
end()Gets iterator for a non-existent element behind the end of the collection.
end() constGets iterator for a non-existent element behind the end of the const-qualified collection.
Exists(System::Predicate<T>)Checks if element adhering to specific predicate exists in list.
Find(System::Predicate<T>)Looks for element adhering to specific predicate.
FindAll(System::Predicate<T>)Looks for elements adhering to specific predicate.
FindIndex(System::Predicate<T>)Looks for element adhering to specific predicate.
FindIndex(int, System::Predicate<T>)Looks for element adhering to specific predicate.
FindIndex(int, int, System::Predicate<T>)Looks for element adhering to specific predicate.
FindLast(System::Predicate<T>)Looks for last element adhering to specific predicate.
ForEach(System::Action<T>)Applies action to all elements in list.
get_Capacity() constGets current list capacity.
get_Count() const overrideGets number of elements in current list.
GetEnumerator() overrideGets enumerator to iterate through list elements.
GetRange(int, int)Creates slice of list.
idx_get(int) const overrideGets element at specific position.
idx_set(int, T) overrideSets element at specific position.
IndexOf(const T&) const overrideGets first index of specific item.
IndexOf(const T&, int) constLooks for specific item in list.
Insert(int, const T&) overrideInserts item at specified position.
InsertRange(int, IEnumerablePtr)Inserts data range at specific position.
LastIndexOf(const T&) constSearches for the specified object and returns the zero-based index of the last occurrence within the entire list.
LastIndexOf(const T&, int32_t) constSearches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the List that extends from the first element to the specified index.
LastIndexOf(const T&, int32_t, int32_t) constSearches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the List that contains the specified number of elements and ends at the specified index.
List()Creates empty list.
List(int)Creates list with pre-defined capacity.
List(IEnumerablePtr)Copy constructor.
operator[](int)Accessor function.
operator[](int) constAccessor function.
rbegin()Gets a reverse iterator to the last element of collection (first in reverse).
rbegin() constGets a reverse iterator to the last element of the const-qualified collection (first in reverse).
Remove(const T&) overrideRemoves first instance of specific item from list.
RemoveAll(Predicate<T>)Removes all elements matching specific predicate.
RemoveAt(int) overrideRemoves item at specified position.
RemoveRange(int, int)Removes slice of list.
rend()Gets a reverse iterator for a non-existent element before the start of the collection.
rend() constGets a reverse iterator for a non-existent element before the start of the const-qualified collection.
Reverse()Reverses elements order of the whole list.
Reverse(int, int)Reverses elements order of the list slice.
set_Capacity(int)Sets list capacity.
Sort(const SharedPtr<System::Collections::Generic::IComparer<T>>&)Sorts elements in the list.
Sort()Sorts elements in the list using default comparator.
Sort(int, int, SharedPtr<System::Collections::Generic::IComparer<T>>)Sorts elements in the list slice.
Sort(Comparison<T>, bool)Sorts elements in the list.
ToArray() constConverst list to array.
TrimExcess()Makes list capacity to fit its size.
TrueForAll(System::Predicate<T>)Determines whether every element in the collection matches the conditions defined by the specified predicate.
virtualizeBeginConstIterator() const overrideGets the implementation of begin const iterator for the current container.
virtualizeBeginIterator() overrideGets the implementation of begin iterator for the current container.
virtualizeEndConstIterator() const overrideGets the implementation of end const iterator for the current container.
virtualizeEndIterator() overrideGets the implementation of end iterator for the current container.

Typedefs

TypedefDescription
ValueTypeThis type.
BaseTypeInterface type.
vector_tRTTI information.
iteratorIterator type.
const_iteratorConst iterator type.
reverse_iteratorReverse iterator type.
const_reverse_iteratorConst reverse iterator type.
IEnumerablePtrContainer holding elements of same type we hold.
IEnumeratorPtrEnumerator type.

Remarks

List - wrapper around std::vector to be used in translated code. Requires operator == to be impemented for element type. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

#include <system/collections/list.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

int main()
{
  // Create the first list.
  auto list1 = MakeObject<List<int>>();

  // Fill the first list.
  list1->Add(3);
  list1->Add(1);
  list1->Add(-5);
  list1->Add(8);

  // Sort the first list.
  // The first list items will be: {-5, 1, 3, 8}
  list1->Sort();

  // Remove the item at index 2.
  // The first list items will be: {-5, 1, 8}
  list1->RemoveAt(2);

  // Insert the item to index 1.
  // The first list items will be: {-5, 15, 1, 8}
  list1->Insert(1, 15);

  // Create the second list.
  auto list2 = MakeObject<List<int>>();

  // Fill the second list.
  list2->Add(10);
  list2->Add(20);
  list2->Add(30);

  // Append elements from the second list to the first one.
  list1->AddRange(list2);

  // Print the first list items.
  for (const auto item: list1)
  {
    std::cout << item << ' ';
  }

  return 0;
}
/*
This code example produces the following output:
-5 15 1 8 10 20 30
*/

See Also