xtd 0.2.0
Loading...
Searching...
No Matches
collections

Definition

Contains collections definitions.

Modules

 generic
 Contains generic collections definitions.
 
 object model
 Contains object model collections definitions.
 
 specialized
 Contains specialized collections definitions.
 

Classes

class  xtd::collections::bit_array
 Manages a compact array of bit values, which are represented as booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0). More...
 
class  xtd::forms::layout::arranged_element_collection< type_t, sorter_t >
 Represents a collection of objects. More...
 

Typedefs

using xtd::collections::any_pair = xtd::collections::dictionary_entry
 Implements a xtd::collections::generic::key_value_pair with the key and the value strongly typed to be std::any.
 
using xtd::collections::array_list = generic::list< xtd::any_object >
 Represents a collection of std::any.
 
using xtd::collections::comparer = xtd::collections::generic::comparer< xtd::any_object >
 Exposes a method that compares two objects.
 
using xtd::collections::dictionary_entry = xtd::collections::generic::key_value_pair< xtd::any_object, xtd::any_object >
 Defines a dictionary key/value pair that can be set or retrieved.
 
using xtd::collections::enumerator = generic::enumerator< xtd::any_object >
 Supports a simple iteration over a non-generic collection.
 
using xtd::collections::hashtable = xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >
 Represents a collection of key/value pairs that are organized based on the hash code of the key.
 
using xtd::collections::icollection = generic::icollection< xtd::any_object >
 Defines size, enumerators, and synchronization methods for all nongeneric collections.
 
using xtd::collections::icomparer = generic::icomparer< xtd::any_object >
 interface IComparer exposes a method that compares two objects.
 
using xtd::collections::idictionary = generic::idictionary< xtd::any_object, xtd::any_object >
 interface IComparer exposes a method that compares two objects.
 
using xtd::collections::ienumerable = generic::ienumerable< xtd::any_object >
 Exposes an enumerator, which supports a simple iteration over a non-generic collection.
 
using xtd::collections::ienumerator = generic::ienumerator< xtd::any_object >
 Supports a simple iteration over a non-generic collection.
 
using xtd::collections::iequality_comparer = generic::iequality_comparer< xtd::any_object >
 Defines methods to support the comparison of objects for equality.
 
using xtd::collections::ilist = generic::ilist< xtd::any_object >
 Represents a non-generic collection of objects that can be individually accessed by index.
 
using xtd::collections::queue = generic::queue< xtd::any_object >
 Represents a first-in, first-out collection of objects.
 
using xtd::collections::sorted_list = generic::list< xtd::any_object >
 Represents a collection of std::any.
 
using xtd::collections::stack = generic::stack< xtd::any_object >
 Represents a collection of std::any.
 
using xtd::collections::vector_list = array_list
 Represents a collection of std::any.
 

Typedef Documentation

◆ any_pair

#include <xtd.core/include/xtd/collections/any_pair.hpp>

Implements a xtd::collections::generic::key_value_pair with the key and the value strongly typed to be std::any.

xtd::collections::generic::key_value_pair< xtd::any_object, xtd::any_object > dictionary_entry
Defines a dictionary key/value pair that can be set or retrieved.
Definition dictionary_entry.hpp:26
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
Header
#include <xtd/collections/any_pair>
Namespace
xtd::collections
Library
xtd.core
Deprecated:
Replaced by xtd::collections::dictionary_entry - Will be removed in version 0.4.0.

◆ array_list

#include <xtd.core/include/xtd/collections/array_list.hpp>

Represents a collection of std::any.

Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
Header
#include <xtd/collections/array_list>
Namespace
xtd::collections
Library
xtd.core
Examples
The following example shows hows to use xtd::collections::array_list.
#include <xtd/collections/array_list>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections;
template<typename collection_t>
void print_values(const collection_t& my_list) {
for (auto obj : my_list)
console::write(" {0}", obj);
}
auto main() -> int {
// Creates and initializes a new vector_list.
auto my_vl = array_list {};
my_vl.emplace_back("Hello");
my_vl.emplace_back("World");
my_vl.emplace_back("!");
// Displays the properties and values of the vector_list.
console::write_line(" size: {0}", my_vl.size());
console::write_line(" Capacity: {0}", my_vl.capacity());
console::write(" Values:");
print_values(my_vl);
}
// This code produces the following output :
//
// my_vl
// size: 3
// Capacity: 4
// Values: Hello World !
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
Represents the standard input, output, and error streams for console applications.
Definition console.hpp:36
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Remarks
TTo add a class, structure or any other type unknown to xtd, you need to implement the xtd::iequatable and xtd::icompoabale interfaces or overrride the == and < operetors.

◆ comparer

#include <xtd.core/include/xtd/collections/comparer.hpp>

Exposes a method that compares two objects.

Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
Header
#include <xtd/collections/comparer>
Namespace
xtd::collections
Library
xtd.core

◆ dictionary_entry

#include <xtd.core/include/xtd/collections/dictionary_entry.hpp>

Defines a dictionary key/value pair that can be set or retrieved.

Header
#include <xtd/collections/dictionary_entry>
Namespace
xtd::collections
Library
xtd.core

◆ enumerator

#include <xtd.core/include/xtd/collections/enumerator.hpp>

Supports a simple iteration over a non-generic collection.

Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Header
#include <xtd/collections/enumerator>
Namespace
xtd::collections
Library
xtd.core
Remarks
The xtd::collections::enumerator class is used to encapsulate an xtd::collections::ienumerator.

◆ hashtable

#include <xtd.core/include/xtd/collections/hashtable.hpp>

Represents a collection of key/value pairs that are organized based on the hash code of the key.

Represents a collection of keys and values.
Definition dictionary.hpp:67
Header
#include <xtd/collections/hashtable>
Namespace
xtd::collections
Library
xtd.core
Remarks
Each element is a key/value pair stored in a xtd::collections::dictionary_entry object. A key cannot be null, but a value can be.
The objects used as keys by a xtd::collections::hashtable are required to override the xtd::object::get_hash_code method (or the xtd::ihash_code_provider interface) and the xtd::object::equals method (or the xtd::icomparer interface). The implementation of both methods and interfaces must handle case sensitivity the same way; otherwise, the xtd::collections::hashtable might behave incorrectly. For example, when creating a xtd::collections::hashtable, you must use the xtd::case_insensitive_hash_code_provider class (or any case-insensitive xtd::ihash_code_provider implementation) with the xtd::case_insensitive_comparer class (or any case-insensitive xtd::icComparer implementation).
Furthermore, these methods must produce the same results when called with the same parameters while the key exists in the xtd::collections::hashtable. An alternative is to use a xtd::collections::hashtable constructor with an xtd::iequality_comparer parameter. If key equality were simply reference equality, the inherited implementation of xtd::object::get_hash_code and xtd::object::equals would suffice.
Key objects must be immutable as long as they are used as keys in the xtd::collections::hashtable.
When an element is added to the xtd::collections::hashtable, the element is placed into a bucket based on the hash code of the key. Subsequent lookups of the key use the hash code of the key to search in only one particular bucket, thus substantially reducing the number of key comparisons required to find an element.
The load factor of a xtd::collections::hashtable determines the maximum ratio of elements to buckets. Smaller load factors cause faster average lookup times at the cost of increased memory consumption. The default load factor of 1.0 generally provides the best balance between speed and size. A different load factor can also be specified when the xtd::collections::hashtable is created.
As elements are added to a xtd::collections::hashtable, the actual load factor of the xtd::collections::hashtable increases. When the actual load factor reaches the specified load factor, the number of buckets in the xtd::collections::hashtable is automatically increased to the smallest prime number that is larger than twice the current number of xtd::collections::hashtable buckets.
Each key object in the xtd::collections::hashtable must provide its own hash function, which can be accessed by calling GetHash. However, any object implementing IHashCodeProvider can be passed to a xtd::collections::hashtable constructor, and that hash function is used for all objects in the table
The capacity of a xtd::collections::hashtable is the number of elements the xtd::collections::hashtable can hold. As elements are added to a xtd::collections::hashtable, the capacity is automatically increased as required through reallocation.
The foreach statement returns an object of the type of the elements in the collection. Since each element of the xtd::collections::hashtable is a key/value pair, the element type is not the type of the key or the type of the value. Instead, the element type is xtd::collections::dictionary_entry. For example:
for (xtd::collections::dictionary_entry de : my_hashtable) {
// ...
}
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.
Because serializing and deserializing an enumerator for a xtd::collections::hashtable can cause the elements to become reordered, it is not possible to continue enumeration without calling the Reset method.
Note
Because keys can be inherited and their behavior changed, their absolute uniqueness cannot be guaranteed by comparisons using the Equals method.
Examples
The following example shows how to create, initialize and perform various functions to a xtd::collections::hashtable and how to print out its keys and values.
#include <xtd/collections/hashtable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections;
auto main() -> int {
// Create a new hash table.
//
hashtable open_with;
// Add some elements to the hash table. There are no
// duplicate keys, but some of the values are duplicates.
open_with["txt"] = "notepad.exe";
open_with["bmp"] = "paint.exe";
open_with["dib"] = "paint.exe";
open_with["rtf"] = "wordpad.exe";
// The Item property is the default property, so you
// can omit its name when accessing elements.
console::write_line("For key = \"rtf\", value = {0}.", open_with["rtf"]);
// The default Item property can be used to change the value
// associated with a key.
open_with["rtf"] = "winword.exe";
console::write_line("For key = \"rtf\", value = {0}.", open_with["rtf"]);
// If a key does not exist, setting the default Item property
// for that key adds a new key/value pair.
open_with["doc"] = "winword.exe";
// contains can be used to test keys before inserting
// them.
if (!open_with.contains("ht")) {
open_with["ht"] = "hypertrm.exe";
console::write_line("Value added for key = \"ht\": {0}", open_with["ht"]);
}
// When you use foreach to enumerate hash table elements,
// the elements are retrieved as xtd::collections::generic::key_value_pair objects.
for (auto de : open_with)
console::write_line("Key = {0}, Value = {1}", de.first, de.second);
// Use the Remove method to remove a key/value pair.
console::write_line("\nerase(\"doc\")");
open_with.erase("doc");
if (!open_with.contains("doc"))
console::write_line("Key \"doc\" is not found.");
}
// This code produces the following output :
//
// For key = "rtf", value = wordpad.exe.
// For key = "rtf", value = winword.exe.
// Value added for key = "ht": hypertrm.exe
//
// Key = ht, Value = hypertrm.exe
// Key = doc, Value = winword.exe
// Key = bmp, Value = paint.exe
// Key = rtf, Value = winword.exe
// Key = dib, Value = paint.exe
// Key = txt, Value = notepad.exe
//
// erase("doc")
// Key "doc" is not found.
iterator erase(const_iterator pos)
Erases elements.
Definition dictionary.hpp:938
bool contains(const key_t &key) const noexcept
Checks if the container contains element with specific key.
Definition dictionary.hpp:795

◆ icollection

#include <xtd.core/include/xtd/collections/icollection.hpp>

Defines size, enumerators, and synchronization methods for all nongeneric collections.

Defines methods to manipulate generic collections.
Definition icollection.hpp:45
Header
#include <xtd/collections/icollection>
Namespace
xtd::collections
Library
xtd.core
Remarks
The xtd::collections::icollection interface is the base interface for classes in the xtd::collections namespace. Its generic equivalent is the xtd::collections::genric::icollection <type_t> interface.
The xtd::collections::icollection interface extends xtd::collections::ienumerable; xtd::collections::idictionary and xtd::collections::ilist are more specialized interfaces that extend xtd::collections::icollection. An xtd::collections::idictionary implementation is a collection of key/value pairs, like the xtd::collections::hashtable class. An xtd::collections::ilist implementation is a collection of values and its members can be accessed by index, like the xtd::collections::array_list class.
Some collections that limit access to their elements, such as the xtd::collections::queue class and the xtd::collections::stack class, directly implement the xtd::collections::icollection interface.
If neither the xtd::collections::idictionary interface nor the xtd::collections::ilist interface meet the requirements of the required collection, derive the new collection class from the xtd::collections::icollection interface instead for more flexibility.
For the generic version of this interface, see xtd::collections::generic::icollection <type_t>.

◆ icomparer

#include <xtd.core/include/xtd/collections/icomparer.hpp>

interface IComparer exposes a method that compares two objects.

Exposes a method that compares two objects.
Definition icomparer.hpp:30
Header
#include <xtd/collections/icomparer>
Namespace
xtd::collections
Library
xtd.core

◆ idictionary

#include <xtd.core/include/xtd/collections/idictionary.hpp>

interface IComparer exposes a method that compares two objects.

Represents a generic collection of key/value pairs.
Definition idictionary.hpp:44
Header
#include <xtd/collections/idictionary>
Namespace
xtd::collections
Library
xtd.core

◆ ienumerable

#include <xtd.core/include/xtd/collections/ienumerable.hpp>

Exposes an enumerator, which supports a simple iteration over a non-generic collection.

Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Header
#include <xtd/collections/ienumerable>
Namespace
xtd::collections
Library
xtd.core
Examples
The following code example demonstrates the best practice for iterating a custom collection by implementing the xtd::collections::ienumerable and xtd::collections::ienumerator interfaces. In this example, members of these interfaces are not explicitly called, but they are implemented to support the use of for each to iterate through the collection. This example is a complete Console app.
#include <xtd/collections/array_list>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
class program {
public:
// Simple business object.
struct person : public object, public iequatable<person>, public icomparable<person> {
public:
person() = default;
person(const string& first_name, const string last_name) : first_name {first_name}, last_name {last_name} {}
string first_name;
string last_name;
int32 compare_to(const person& o) const noexcept override {
if (first_name == o.first_name && last_name == o.last_name) return 0;
if (first_name > o.first_name || (first_name == o.first_name && last_name > o.last_name)) return 1;
return -1;
}
bool equals(const object& o) const noexcept override {return is<person>(o) && equals(as<person>(o));}
bool equals(const person& o) const noexcept override {return compare_to(o) == 0;}
string to_string() const noexcept override {return string::format("{} {}", first_name, last_name);}
};
// Collection of person objects. This class implements xtd::collections::ienumerable so that it can be used with for each syntax.
class people : public collections::ienumerable {
private:
public:
people(const array<person>& p_array) {
people_ = collections::array_list(p_array.size());
for (auto i = 0_z; i < p_array.size(); ++i)
people_[i] = p_array[i];
}
// Implementation for the xtd::collections::ienumerable::get_enumerator method.
collections::enumerator get_enumerator() const override {
return collections::enumerator {new_ptr<people_enumerator>(people_)};
}
};
// When you implement xtd::collections::ienumerable, you must also implement xtd::collections::ienumerator.
class people_enumerator : public collections::ienumerator {
private:
const collections::array_list& people_;
// Enumerators are positioned before the first element until the first xtd::collections::ienumerator::move_next() call.
size position = collections::array_list::npos;
public:
people_enumerator(const collections::array_list& list) : people_(list) {}
bool move_next() override {return ++position < people_.count();}
void reset() override {position = collections::array_list::npos;}
const any_object& current() const override {
if (position >= people_.size()) throw invalid_operation_exception {};
return people_[position];
}
};
static auto main() -> void {
auto people_array = xtd::array<person> {
person {"John", "Smith"},
person {"Jim", "Johnson"},
person {"Sue", "Rabon"},
};
auto people_list = people {people_array};
for (auto person : people_list)
console::write_line(person);
}
};
startup_(program::main);
// This code produces the following output :
//
// John Smith
// Jim Johnson
// Sue Rabon
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:28
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:59
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
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
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 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
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
The exception that is thrown when the format of an argument does not meet the parameter specification...
Definition invalid_operation_exception.hpp:19
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ current
Specifies the current position within a stream.
@ i
The I key.
@ o
The O key.
Remarks
xtd::collections::ienumerable is the base interface for all non-generic collections that can be enumerated. For the generic version of this interface see xtd::collections::generic::ieumerable <type_t>. xtd::collections::ienumerable contains a single method, xtd::collections::ienumerable::get_enumerator, which returns an xtd::collections::ienumerator. xtd::collections::ienumerator provides the ability to iterate through the collection by exposing a xtd::collections::ienumerator::current property and xtd::collections::ienumerator::move_next and xtd::collections::ienumeraror::reset methods.
It is a best practice to implement xtd::collections::ienumerable and xtd::collections::ienumerator on your collection classes to enable the for each syntax, however implementing xtd::collections::ienumerable is not required. If your collection does not implement xtd::collections::ienumerable, you must still follow the iterator pattern to support this syntax by providing a xtd::collections::ienumerable::get_enumerator method that returns an interface, class or struct. You must provide a class that contains a xtd::collections::ienumerator::current property, and xtd::collections::ienumerator::move_next and Reset methods as described by xtd::collections::ienumerator, but the class does not have to implement xtd::collections::ienumerator.

◆ ienumerator

#include <xtd.core/include/xtd/collections/ienumerator.hpp>

Supports a simple iteration over a non-generic collection.

Header
#include <xtd/collections/ienumerator>
Namespace
xtd::collections
Library
xtd.core

The following code example demonstrates the best practice for iterating a custom collection by implementing the xtd::collections::ienumerable and xtd::collections::ienumerator interfaces. In this example, members of these interfaces are not explicitly called, but they are implemented to support the use of for each to iterate through the collection. This example is a complete Console app.

#include <xtd/collections/array_list>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
class program {
public:
// Simple business object.
struct person : public object, public iequatable<person>, public icomparable<person> {
public:
person() = default;
person(const string& first_name, const string last_name) : first_name {first_name}, last_name {last_name} {}
string first_name;
string last_name;
int32 compare_to(const person& o) const noexcept override {
if (first_name == o.first_name && last_name == o.last_name) return 0;
if (first_name > o.first_name || (first_name == o.first_name && last_name > o.last_name)) return 1;
return -1;
}
bool equals(const object& o) const noexcept override {return is<person>(o) && equals(as<person>(o));}
bool equals(const person& o) const noexcept override {return compare_to(o) == 0;}
string to_string() const noexcept override {return string::format("{} {}", first_name, last_name);}
};
// Collection of person objects. This class implements xtd::collections::ienumerable so that it can be used with for each syntax.
class people : public collections::ienumerable {
private:
public:
people(const array<person>& p_array) {
people_ = collections::array_list(p_array.size());
for (auto i = 0_z; i < p_array.size(); ++i)
people_[i] = p_array[i];
}
// Implementation for the xtd::collections::ienumerable::get_enumerator method.
collections::enumerator get_enumerator() const override {
return collections::enumerator {new_ptr<people_enumerator>(people_)};
}
};
// When you implement xtd::collections::ienumerable, you must also implement xtd::collections::ienumerator.
class people_enumerator : public collections::ienumerator {
private:
const collections::array_list& people_;
// Enumerators are positioned before the first element until the first xtd::collections::ienumerator::move_next() call.
size position = collections::array_list::npos;
public:
people_enumerator(const collections::array_list& list) : people_(list) {}
bool move_next() override {return ++position < people_.count();}
void reset() override {position = collections::array_list::npos;}
const any_object& current() const override {
if (position >= people_.size()) throw invalid_operation_exception {};
return people_[position];
}
};
static auto main() -> void {
auto people_array = xtd::array<person> {
person {"John", "Smith"},
person {"Jim", "Johnson"},
person {"Sue", "Rabon"},
};
auto people_list = people {people_array};
for (auto person : people_list)
console::write_line(person);
}
};
startup_(program::main);
// This code produces the following output :
//
// John Smith
// Jim Johnson
// Sue Rabon
Remarks
xtd::collections::ienumerator is the base interface for all non-generic enumerators. Its generic equivalent is the xtd::collections::generic::iznumerator <type_t> interface.
The for each statement of the C++ language hides the complexity of the enumerators. Therefore, using for each is recommended instead of directly manipulating the enumerator.
Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.
The xtd::collections::ienumerator::reset method is provided for COM interoperability and does not need to be fully implemented; instead, the implementer can throw a xtd::not_supported_exception.
Initially, the enumerator is positioned before the first element in the collection. You must call the xtd::collections::ienumerator::MMoveN_next method to advance the enumerator to the first element of the collection before reading the value of xtd::collections::ienumerator::current; otherwise, xtd::collections::ienumerator::current is undefined.
xtd::collections::ienumerator::current returns the same object until either xtd::collections::ienumerator::move_next or xtd::collections::ienumerator::reset is called. xtd::collections::ienumerator::move_next sets xtd::collections::ienumerator::current to the next element.
If xtd::collections::ienumerator::move_next passes the end of the collection, the enumerator is positioned after the last element in the collection and xtd::collections::ienumerator::move_next returns false. When the enumerator is at this position, subsequent calls to xtd::collections::ienumerator::move_next also return false. If the last call to xtd::collections::ienumerator::move_next returned false, xtd::collections::ienumerator::current is undefined.
To set xtd::collections::ienumerator::current to the first element of the collection again, you can call Reset, if it's implemented, followed by xtd::collections::ienumerator::move_next. If xtd::collections::ienumerator::reset is not implemented, you must create a new enumerator instance to return to the first element of the collection.
If changes are made to the collection, such as adding, modifying, or deleting elements, the behavior of the enumerator is undefined.
The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

◆ iequality_comparer

#include <xtd.core/include/xtd/collections/iequality_comparer.hpp>

Defines methods to support the comparison of objects for equality.

Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Header
#include <xtd/collections/iequality_comparer>
Namespace
xtd::collections
Library
xtd.core
Remarks
This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality, and specify that this definition be used with a collection type that accepts the xtd::collections::iequality_comparer interface. In the xtd framework, constructors of the xtd::collections::hashtable, xtd::collections::specialized::name_value_collection, and xtd::collections::specialized::ordered_dictionary collection types accept this interface.
For the generic version of this interface, see xtd::collections::generic::iequality_comparer <type_t>.
The xtd::collections::iequality_comparer interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the xtd::collections::icomparer interface.

◆ ilist

#include <xtd.core/include/xtd/collections/ilist.hpp>

Represents a non-generic collection of objects that can be individually accessed by index.

Represents a collection of objects that can be individually accessed by index.
Definition ilist.hpp:41
Header
#include <xtd/collections/ilist>
Namespace
xtd::collections
Library
xtd.core

par Examples The following example demonstrates the implementation of the xtd::collections::ilist interface to create a simple, fixed-size list.

#include <xtd/collections/array_list>
#include <xtd/array>
#include <xtd/console>
#include <xtd/not_implemented_exception>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() -> void {
auto test = simple_list();
// Populate the List.
console::write_line("Populate the List");
test.add("one");
test.add("two");
test.add("three");
test.add("four");
test.add("five");
test.add("six");
test.add("seven");
test.add("eight");
test.print_contents();
console::write_line();
// Remove elements from the list.
console::write_line("Remove elements from the list");
test.remove("six");
test.remove("eight");
test.print_contents();
console::write_line();
// Add an element to the end of the list.
console::write_line("Add an element to the end of the list");
test.add("nine");
test.print_contents();
console::write_line();
// Insert an element into the middle of the list.
console::write_line("Insert an element into the middle of the list");
test.insert(4, "number");
test.print_contents();
console::write_line();
// Check for specific elements in the list.
console::write_line("Check for specific elements in the list");
console::write_line("List contains \"three\": {}", test.contains("three"));
console::write_line("List contains \"ten\": {}", test.contains("ten"));
}
class simple_list : public object, public collections::ilist {
private:
size count_;
public:
inline static constexpr size npos = ilist::npos;
simple_list() {count_ = 0;}
void print_contents() const noexcept {
console::write_line("List has a capacity of {} and currently has {} elements.", contents_.size(), count_);
console::write("List contents:");
for (auto i = 0_z; i < count(); ++i)
console::write(" {}", contents_[i]);
console::write_line();
}
// xtd::collections::iist Members
bool is_fixed_size() const noexcept override {return true;}
bool is_read_only() const noexcept override {return false;}
void add(const any_object& value) override {
if (count_ < contents_.size()) {
contents_[count_] = value;
count_++;
}
}
void clear() override {
count_ = 0;
}
bool contains(const any_object& value) const noexcept override {
for (auto i = 0_z; i < count(); ++i)
if (contents_[i] == value) return true;
return false;
}
size index_of(const any_object& value) const noexcept override {
for (auto i = 0_z; i < count(); ++i)
if (contents_[i] == value) return i;
return npos;
}
void insert(size index, const any_object& value) override {
if (count_ + 1 <= contents_.size() && index < count()) {
++count_;
for (size i = count() - 1; i > index; --i)
contents_[i] = contents_[i - 1];
contents_[index] = value;
}
}
bool remove(const any_object& value) override {
auto index = index_of(value);
remove_at(index);
return index != npos;
}
void remove_at(size index) override {
if (index < count()) {
for (size i = index; i < count() - 1; ++i)
contents_[i] = contents_[i + 1];
--count_;
}
}
const any_object& operator [] (size index) const override {
return contents_[index];
}
any_object& operator [] (size index) override {
return contents_[index];
}
// xtd::collections::icollection members.
size count() const noexcept override {return count_;}
bool is_synchronized() const noexcept override {return false;}
// Return the current instance since the underlying store is not
// publicly available.
const object& sync_root() const noexcept override {return *this;}
void copy_to(xtd::array<any_object>& array, size index) const noexcept override {
for (auto i = 0_z; i < count(); ++i)
array[index + i] = contents_[i];
}
// xtd::collections::ienumerable Members
collections::enumerator get_enumerator() const override {
// Refer to the xtd::collection::ienumerator documentation for an example of
// implementing an enumerator.
throw not_implemented_exception {"The method or operation is not implemented."};
}
};
};
startup_(program::main);
// This code produces the following output :
//
// Populate the List
// List has a capacity of 8 and currently has 8 elements.
// List contents: one two three four five six seven eight
//
// Remove elements from the list
// List has a capacity of 8 and currently has 6 elements.
// List contents: one two three four five seven
//
// Add an element to the end of the list
// List has a capacity of 8 and currently has 7 elements.
// List contents: one two three four five seven nine
//
// Insert an element into the middle of the list
// List has a capacity of 8 and currently has 8 elements.
// List contents: one two three four number five seven nine
//
// Check for specific elements in the list
// List contains "three": true
// List contains "ten": false
The exception that is thrown when a requested method or operation is not implemented.
Definition not_implemented_exception.hpp:19
@ clear
The CLEAR key.
@ add
The Add key.
@ insert
The INS (INSERT) key.
Remarks
xtd::collections::ilist is a descendant of the xtd::collections::icollection interface and is the base interface of all non-generic lists. xtd::collections::ilist implementations fall into three categories: read-only, fixed-size, and variable-size. A read-only xtd::collections::ilist cannot be modified. A fixed-size xtd::collections::ilist does not allow the addition or removal of elements, but it allows the modification of existing elements. A variable-size xtd::collections::ilist allows the addition, removal, and modification of elements.
For the generic version of this interface, see xtd::collections::generic::ilist <type_t>.

◆ queue

#include <xtd.core/include/xtd/collections/queue.hpp>

Represents a first-in, first-out collection of objects.

generic::queue< xtd::any_object > queue
Represents a first-in, first-out collection of objects.
Definition queue.hpp:27
std::stack< type_t, container_t > queue
Represents a collection of objects that is maintained in sorted order.
Definition queue.hpp:39
Header
#include <xtd/collections/queue>
Namespace
xtd::collections
Library
xtd.core

◆ sorted_list

#include <xtd.core/include/xtd/collections/sorted_list.hpp>

Represents a collection of std::any.

Header
#include <xtd/collections/sorted_list>
Namespace
xtd::collections
Library
xtd.core

◆ stack

#include <xtd.core/include/xtd/collections/stack.hpp>

Represents a collection of std::any.

generic::stack< xtd::any_object > stack
Represents a collection of std::any.
Definition stack.hpp:31
std::stack< type_t, container_t > stack
Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified typ...
Definition stack.hpp:34
Header
#include <xtd/collections/stack>
Namespace
xtd::collections
Library
xtd.core
Examples
The following example shows hows to use xtd::collections::stack.
Remarks
TTo add a class, structure or any other type unknown to xtd, you need to implement the xtd::iequatable and xtd::icompoabale interfaces or overrride the == and < operetors.

◆ vector_list

#include <xtd.core/include/xtd/collections/vector_list.hpp>

Represents a collection of std::any.

Header
#include <xtd/collections/vector_list>
Namespace
xtd::collections
Library
xtd.core
Examples
The following example shows hows to use xtd::collections::array_list.
#include <xtd/collections/array_list>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections;
template<typename collection_t>
void print_values(const collection_t& my_list) {
for (auto obj : my_list)
console::write(" {0}", obj);
}
auto main() -> int {
// Creates and initializes a new vector_list.
auto my_vl = array_list {};
my_vl.emplace_back("Hello");
my_vl.emplace_back("World");
my_vl.emplace_back("!");
// Displays the properties and values of the vector_list.
console::write_line(" size: {0}", my_vl.size());
console::write_line(" Capacity: {0}", my_vl.capacity());
console::write(" Values:");
print_values(my_vl);
}
// This code produces the following output :
//
// my_vl
// size: 3
// Capacity: 4
// Values: Hello World !
Deprecated:
Replaced by xtd::collections::array_list - Will be removed in version 0.4.0.