xtd 1.0.0
Loading...
Searching...
No Matches
xtd::collections::generic::idictionary< key_t, value_t > Class Template Referenceabstract
Inheritance diagram for xtd::collections::generic::idictionary< key_t, value_t >:
xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::collections::generic::extensions::collection_common< xtd::collections::generic::key_value_pair< key_t, value_t >, icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > > xtd::interface xtd::collections::generic::ienumerable_abstract xtd::collections::generic::extensions::enumerable_iterators< xtd::collections::generic::key_value_pair< key_t, value_t >, xtd::collections::generic::ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > > xtd::collections::generic::extensions::enumerable< ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > >, xtd::collections::generic::key_value_pair< key_t, value_t > > xtd::collections::generic::dictionary< xtd::intptr, xtd::ptr< collection_type > > xtd::collections::generic::dictionary< key_type, mapped_type > xtd::collections::generic::dictionary< xtd::string, xtd::string > xtd::collections::generic::dictionary< xtd::string, xtd::any_object > xtd::collections::generic::dictionary< intptr, item > xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t > xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >

Definition

template<typename key_t, typename value_t>
class xtd::collections::generic::idictionary< key_t, value_t >

Represents a generic collection of key/value pairs.

Definition
template<typename key_t, typename value_t>
class idictionary : public xtd::collections::generic::icollection<xtd::collections::generic::key_value_pair<key_t, value_t>>;
Defines methods to manipulate generic collections.
Definition icollection.hpp:45
Represents a generic collection of key/value pairs.
Definition idictionary.hpp:47
Header
#include <xtd/collections/generic/idictionary>
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
The xtd::collections::generic::idictionary <key_t, value_t> interface is the base interface for generic collections of key/value pairs.
Each element is a key/value pair stored in a xtd::collections::generic::key_value_pair <key_t, value_t> object.
Each pair must have a unique key. Implementations can vary in whether they allow key to be empty. The value can be empty and does not have to be unique. The idictionary <key_t, value_t> interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.
The for each statement returns an object of the type of the elements in the collection. Since each element of the xtd::collections::generic::idictionary <key_t, value_t> 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::generic::key_value_pair <key_t, value_t>. For example:
for (const key_value_pair<int, string>& kvp : my_dictionary)
console::write_line("key = {}, value = {}", kvp.key(), kvp.value());
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
Or with auto key type and the value type. For example:
for (const auto& [key, value] : my_dictionary)
console::write_line("key = {}, value = {}", key, value);

Public Aliases

using key_type
 Represents the dictionary key type.
using mapped_type
 Represents the dictionary mapped type.
using value_type
 Represents the xtd::collections::generic::idictionary value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using key_collection
 Represents the idictionary key collection type.
using value_collection
 Represents the idictionary value collection type.

Public Properties

virtual auto count () const noexcept -> xtd::usize=0
 Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
virtual auto is_read_only () const noexcept -> bool=0
 Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.
virtual auto is_synchronized () const noexcept -> bool=0
 Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).
virtual auto keys () const noexcept -> key_collection=0
 Gets an xtd::collections::generic::icollection <type_t> containing the keys of the xtd::collections::generic::idictionary <key_t, value_t>.
virtual auto sync_root () const noexcept -> const xtd::object &=0
 Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
virtual auto values () const noexcept -> value_collection=0
 Gets an xtd::collections::generic::icollection <type_t> containing the values of the xtd::collections::generic::idictionary <key_t, value_t>.

Public Methods

virtual auto add (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> void=0
 Adds an item to the xtd::collections::generic::icollection <type_t>.
virtual auto add (const key_t &key, const value_t &value) -> void=0
 Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.
virtual auto clear () -> void=0
 Removes all items from the xtd::collections::generic::icollection <type_t>.
virtual auto contains (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) const noexcept -> bool=0
 Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.
virtual auto contains_key (const key_t &key) const noexcept -> bool=0
 Determines whether the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key.
virtual auto copy_to (xtd::array< xtd::collections::generic::key_value_pair< key_t, value_t > > &array, xtd::usize array_index) const -> void=0
 Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array, starting at a particular xtd::array index.
virtual auto get_enumerator () const -> xtd::collections::generic::enumerator< xtd::collections::generic::key_value_pair< key_t, value_t > >=0
 Returns an enumerator that iterates through a collection.
virtual auto remove (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> bool=0
 Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
virtual auto remove (const key_t &key) noexcept -> bool=0
 Removes the element with the specified key from the xtd::collections::generic::idictionary <key_t, value_t>.
virtual auto try_get_value (const key_t &key, value_t &value) const -> bool=0
 Gets the value associated with the specified key.

Public Operators

virtual auto operator[] (const key_t &key) -> value_t &=0
 Gets the element with the specified key.

Additional Inherited Members

using value_type
 Represents the xtd::collections::generic::icollection value type.
using value_type
 Represents the xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of enumerable value type.
using const_iterator
 Represents the const iterator of enumerable value type.
using enumerable_type
 Represents the ienumerable enumerable type.
using source_type
 Represents the ienumerable source type.
using ienumerable
 Represents the ienumerable value type.
using list
 Represents the list value type.
virtual auto begin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cbegin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cend () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
virtual auto end () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
auto aggregate (const std::function< xtd::collections::generic::key_value_pair< key_t, value_t >(const xtd::collections::generic::key_value_pair< key_t, value_t > &, const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &funcfunc) const -> xtd::collections::generic::key_value_pair< key_t, value_t >
 Applies an accumulator function over a sequence.
auto all (const std::function< bool(const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &predicatepredicate) const -> bool
 Determines whether all elements of a sequence satisfy a condition.
auto any () const noexcept -> bool
 Determines whether a sequence contains any elements.
auto append (const xtd::collections::generic::key_value_pair< key_t, value_t > &element) const noexcept
 Appends a value to the end of the sequence.
auto as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
auto average () const noexcept
 Computes the average of a sequence of source_t values.
auto cast () const noexcept
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
auto chunk (xtd::usize size) const
 Splits the elements of a sequence into chunks of size at most size.
auto concat (const ienumerable< xtd::collections::generic::key_value_pair< key_t, value_t > > &second) const noexcept
 Concatenates two sequences.
auto contains (const xtd::collections::generic::key_value_pair< key_t, value_t > &value) const noexcept -> bool
 Determines whether a sequence contains a specified element by using the default equality comparer.
auto count () const noexcept -> xtd::usize
 Returns the number of elements in current sequence.
auto count_by (const std::function< key_t(const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
auto default_if_empty () const noexcept
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
auto distinct () const noexcept
 Returns distinct elements from a sequence by using the default equality comparer to compare values.
auto first_or_default (const std::function< bool(const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &predicatepredicate, const xtd::collections::generic::key_value_pair< key_t, value_t > &default_value) const noexcept -> xtd::collections::generic::key_value_pair< key_t, value_t >
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
auto order () const
 Sorts the elements of a sequence in ascending order.
auto order_by (const std::function< xtd::collections::generic::key_value_pair< key_t, value_t >(const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
auto order_by_descending (const std::function< key_t(const xtd::collections::generic::key_value_pair< key_t, value_t > &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
auto select (auto &&selector) const
 Projects each element of a sequence into a new form.
auto to_array () const noexcept -> xtd::array< xtd::collections::generic::key_value_pair< key_t, value_t > >
 Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto to_list () const noexcept -> xtd::collections::generic::list< xtd::collections::generic::key_value_pair< key_t, value_t > >
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto where (auto &&predicatepredicate) const
 Filters a sequence of values based on a predicate.
virtual auto empty () const noexcept -> bool
 Checks whether the container is empty.
virtual auto size () const noexcept -> xtd::usize
 Gets the number of elements contained in the xtd::collections::generic::icollection <type_t>.
virtual auto operator<< (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > &
 The shift left operator adds an item to the xtd::collections::generic::icollection <type_t>.
virtual auto operator>> (const xtd::collections::generic::key_value_pair< key_t, value_t > &item) -> icollection< xtd::collections::generic::key_value_pair< key_t, value_t > > &
 The shift right operator removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
static auto to_const_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
static auto to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.

Member Typedef Documentation

◆ key_type

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::key_type

Represents the dictionary key type.

◆ mapped_type

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::mapped_type

Represents the dictionary mapped type.

◆ value_type

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::value_type

Represents the xtd::collections::generic::idictionary value type.

◆ iterator

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::iterator

Represents the iterator of xtd::collections::generic::ienumerable value type.

◆ const_iterator

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::const_iterator

Represents the const iterator of xtd::collections::generic::ienumerable value type.

◆ key_collection

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::key_collection

Represents the idictionary key collection type.

◆ value_collection

template<typename key_t, typename value_t>
using xtd::collections::generic::idictionary< key_t, value_t >::value_collection

Represents the idictionary value collection type.

Member Function Documentation

◆ count()

◆ is_read_only()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::is_read_only ( ) const -> bool
nodiscardpure virtualnoexcept

Gets a value indicating whether the xtd::collections::generic::icollection <type_t> is read-only.

Returns
true if the xtd::collections::generic::icollection <type_t> is read-only; otherwise, false.
Remarks
A collection that is read-only does not allow the addition or removal of elements after the collection is created. Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the xtd::collections::generic::icollection <type_t> interface only supports addition and removal operations. For example, the xtd::collections::generic::icollection::is_read_only property of an array that is cast or converted to an xtd::collections::generic::icollection <type_t> object returns true, even though individual array elements can be modified.

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ is_synchronized()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::is_synchronized ( ) const -> bool
nodiscardpure virtualnoexcept

Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).

Returns
true if access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe); otherwise, false.
Remarks
xtd::collections::generic::icollection::sync_root returns an object, which can be used to synchronize access to the xtd::collections::generic::icollection <type_t>.
Most collection classes in the xtd::collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection.
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.
The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
virtual auto sync_root() const noexcept -> const xtd::object &=0
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:68

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ keys()

◆ sync_root()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::sync_root ( ) const -> const xtd::object &
nodiscardpure virtualnoexcept

Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.

Returns
An object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
Remarks
For collections whose underlying store is not publicly available, the expected implementation is to return the current instance. Note that the pointer to the current instance might not be sufficient for collections that wrap other collections; those should return the underlying collection's sync_root property.
Most collection classes in the xts::.collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection. However, derived classes can provide their own synchronized version of the collection using the xtd::collections::generic::icollection::sync_root property. The synchronizing code must perform operations on the xtd::collections::generic::icollection::sync_root property of the collection, not directly on the collection. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the collection instance.
In the absence of a synchronized method on a collection, the expected usage for the xtd::collections::generic::icollection::sync_root looks as follows:
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
// Some operation on the collection, which is now thread safe.
}
@encode
@remarks 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.
@remarks The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
@code
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (const auto& item : my_collection) {
// Insert your code here.
}
}
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:29
Definition enumeration.hpp:12
auto is(xtd::any value) -> bool
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
@ a
The A key.
Definition console_key.hpp:88
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:39

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ values()

◆ add() [1/2]

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::add ( const xtd::collections::generic::key_value_pair< key_t, value_t > & item) -> void
pure virtual

Adds an item to the xtd::collections::generic::icollection <type_t>.

Parameters
itemThe object to add to the xtd::collections::generic::icollection <type_t>.
Exceptions
xtd::not_supported_exceptionThe xtd::collections::generic::icollection <type_t> is read-only.

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ add() [2/2]

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::add ( const key_t & key,
const value_t & value ) -> void
pure virtual

Adds an element with the provided key and value to the xtd::collections::generic::idictionary <key_t, value_t>.

Parameters
keyThe object to use as the key of the element to add.
valueThe object to use as the value of the element to add.
Exceptions
xtd::argument_exceptionAn element with the same key already exists in the xtd::collections::generic::idictionary <key_t, value_t>.
xtd::not_supported_exceptionThe xtd::collections::generic::idictionary <key_t, value_t> is read-only.
Remarks
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >, and xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >.

◆ clear()

◆ contains()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::contains ( const xtd::collections::generic::key_value_pair< key_t, value_t > & item) const -> bool
nodiscardpure virtualnoexcept

Determines whether the xtd::collections::generic::icollection <type_t> contains a specific value.

Parameters
itemThe object to locate in the xtd::collections::generic::icollection <type_t>.
Returns
true if item is found in the xtd::collections::generic::icollection <type_t>; otherwise, false.
Remarks
Implementations can vary in how they determine equality of objects; for example, xtd::collections::generic::list <type_t> uses xtd::collections::generic::compoarer <type_t>::default_comparer, whereas xtd::collections::generic::dictionary <key_t, value_t> allows the user to specify the xtd::collections::generic::icompoarer <type_t> implementation to use for comparing keys.

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ contains_key()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::contains_key ( const key_t & key) const -> bool
nodiscardpure virtualnoexcept

Determines whether the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key.

Parameters
keyThe key to locate in the xtd::collections::generic::idictionary <key_t, value_t>.
Returns
true if the xtd::collections::generic::idictionary <key_t, value_t> contains an element with the key; otherwise, false.
Remarks
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer <type_t>.Default, whereas the xtd::collections::generic::dictionary <key_t, value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t>x implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >, and xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >.

◆ copy_to()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::copy_to ( xtd::array< xtd::collections::generic::key_value_pair< key_t, value_t > > & array,
xtd::usize array_index ) const -> void
pure virtual

Copies the elements of the xtd::collections::generic::icollection <type_t> to an xtd::array, starting at a particular xtd::array index.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::generic::icollection <type_t>. The xtd::array must have zero-based indexing.
array_indexThe zero-based index in array at which copying begins.
Exceptions
xtd::argument_exceptionThe number of elements in the source xtd::collections::generic::icollection <type_t> is greater than the available space from `array_index` to the end of the destination `array`.

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ get_enumerator()

◆ remove() [1/2]

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::remove ( const xtd::collections::generic::key_value_pair< key_t, value_t > & item) -> bool
pure virtual

Removes the first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.

Parameters
itemThe object to remove from the xtd::collections::generic::icollection <type_t>.
Returns
true if item was successfully removed from the xtd::collections::generic::icollection <type_t>; otherwise, false. This method also returns false if item is not found in the original xtd::collections::generic::icollection <type_t>.
Exceptions
xtd::not_supported_exceptionThe xtd::collections::generic::icollection <type_t> is read-only.
Remarks
Implementations can vary in how they determine equality of objects; for example, xtd::collections::generic::list <type_t> uses xtd::collections::generic::compoarer <type_t>::default_comparer, whereas, xtd::collections::generic::dictionary <key_t, value_t> allows the user to specify the xtd::collections::generic::icompoarer <type_t> implementation to use for comparing keys.
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hash table.

Implements xtd::collections::generic::icollection< xtd::collections::generic::key_value_pair< key_t, value_t > >.

◆ remove() [2/2]

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::remove ( const key_t & key) -> bool
pure virtualnoexcept

Removes the element with the specified key from the xtd::collections::generic::idictionary <key_t, value_t>.

Parameters
keyThe key of the element to remove.
Returns
true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original xtd::collections::generic::idictionary <key_t, value_t>.
Remarks
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer <type_t>.Default, whereas the xtd::collections::generic::dictionary <key_t, value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t>x implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >, xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >, and xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >.

◆ try_get_value()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::try_get_value ( const key_t & key,
value_t & value ) const -> bool
nodiscardpure virtual

Gets the value associated with the specified key.

Parameters
keyThe key whose value to get.
valueWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.
Returns
true if the object that implements xtd::collections::generic::idictionary <key_t, value_t> contains an element with the specified key; otherwise, false.
Remarks
This method combines the functionality of the xtd::collections::generic::idictionary::contains_key method and the xtd::collections::generic::idictionary::operator [] property.
If the key is not found, then the value parameter gets the appropriate default value for the type value_t; for example, zero (0) for integer types, false for Boolean types, and null for reference types

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >, and xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >.

◆ operator[]()

template<typename key_t, typename value_t>
virtual auto xtd::collections::generic::idictionary< key_t, value_t >::operator[] ( const key_t & key) -> value_t &
nodiscardpure virtual

Gets the element with the specified key.

Parameters
keyThe key of the element to get.
Returns
The element with the specified key.
Exceptions
xtd::collections::generic::key_not_found_exceptionThe property is retrieved and key is not found.
xtd::not_supported_exceptionThe property is set and the xtd::collections::generic::idictionary <key_t, value_t> is read-only.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: my_collection[key].
You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator [] overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements. @remarks Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys. */ [[nodiscard]] virtual auto operator [](const key_t& key) const -> const value_t& = 0; /** @brief Sets the element with the specified key. @param key The key of the element to set. @return The element with the specified key. @exception xtd::collections::generic::key_not_found_exception The property is retrieved and key is not found. @exception xtd::not_supported_exception The property is set and the xtd::collections::generic::idictionary <key_t, value_t> is read-only. @remarks This property provides the ability to access a specific element in the collection by using the following syntax: my_collection[key]. @remarks You can also use the operator [] to add new elements by setting the value of a key that does not exist in the dictionary; for example, my_collection["my_nonexistent_key"] = my_value. However, if the specified key already exists in the dictionary, setting the operator []` overwrites the old value. In contrast, the xtd::collections::generic::idictionary::add method does not modify existing elements.
Implementations can vary in how they determine equality of objects; for example, the xtd::collections::generic::list <type_t> class uses xtd::collections::generic::comparer::default_comparer, whereas the xtd::collections::generic::dictionary <key_t,value_t> class allows the user to specify the xtd::collections::generic::icomparer <type_t> implementation to use for comparing keys.

Implemented in xtd::collections::generic::dictionary< key_t, value_t, hasher_t, equator_t, allocator_t >, xtd::collections::generic::dictionary< xtd::any_object, xtd::any_object >, xtd::collections::generic::ordered_dictionary< key_t, value_t, allocator_t >, and xtd::collections::generic::ordered_dictionary< xtd::any_object, xtd::any_object >.


The documentation for this class was generated from the following file: