modello struct WinRT:: map_base (C++/WinRT)winrt::map_base struct template (C++/WinRT)
Una classe di base da cui è possibile derivare per implementare una raccolta associativa non osservabile personalizzata.A base class from which you can derive to implement your own custom non-observable associative collection. Per altre informazioni ed esempi di codice, vedere raccolte con C++/WinRT.For more info, and code examples, see Collections with C++/WinRT.
SintassiSyntax
template <typename D, typename K, typename V>
struct map_base : map_view_base<D, K, V, winrt::impl::collection_version>
Parametri modelloTemplate parameters
typename D
il nome del tipo derivato.typename D
Your derived type name.
typename K
il tipo delle chiavi nella raccolta.typename K
The type of the keys in the collection.
typename V
il tipo dei valori della raccolta.typename V
The type of the values in the collection.
RequisitiRequirements
SDK minimo supportato: Windows SDK versione 10.0.17763.0 (Windows 10, versione 1809)Minimum supported SDK: Windows SDK version 10.0.17763.0 (Windows 10, version 1809)
Spazio dei nomi: WinRTNamespace: winrt
L' intestazione % WindowsSdkDir% include<WindowsTargetPlatformVersion > \cppwinrt\winrt\base.h (incluso per impostazione predefinita)Header %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Funzioni membroMember functions
FunzioneFunction | DescrizioneDescription |
---|---|
funzione map_base:: Clearmap_base::Clear function | Rimuove tutti gli elementi dall'oggetto map_base .Removes all elements from the map_base object. |
funzione map_base:: Firstmap_base::First function | Recupera un IIterator che rappresenta il primo elemento nell'oggetto map_base .Retrieves an IIterator representing the first element in the map_base object. |
funzione map_base:: GetViewmap_base::GetView function | Recupera una visualizzazione non modificabile dell'oggetto map_base .Retrieves an immutable view of the map_base object. |
funzione map_base:: HasKeymap_base::HasKey function | Determina se la chiave specificata appartiene a un elemento nell'oggetto map_base .Determines whether the specified key belongs to an element in the map_base object. |
funzione map_base:: Insertmap_base::Insert function | Inserisce o aggiorna un elemento nell'oggetto map_base .Inserts or updates an element in the map_base object. |
funzione map_base:: Lookupmap_base::Lookup function | Cerca l'elemento identificato dalla chiave specificata e recupera il valore corrispondente.Looks up the element identified by the specified key, and retrieves the corresponding value. |
funzione map_base:: Removemap_base::Remove function | Rimuove un elemento dall'oggetto map_base .Removes an element from the map_base object. |
funzione map_base:: sizemap_base::Size function | Recupera il numero di elementi nell'oggetto map_base .Retrieves the number of elements in the map_base object. |
IteratoriIterators
Un map_base è un intervallo e tale intervallo è definito dalle funzioni gratuite interne (ognuna delle quali recupera un iteratore) compatibili con le funzionalità del linguaggio standard.A map_base is a range, and that range is defined by internal free functions (each of which retrieves an iterator) that are compatible with standard language features. Per questo motivo, è possibile enumerare gli elementi in un oggetto map_base con un'istruzione for
basata sull'intervallo.Because of this, you can enumerate the elements in a map_base object with a range-based for
statement.
È anche possibile recuperare un IIterator dalla funzione Map_base:: First e usarlo per scorrere gli elementi di un oggetto map_base .You can also retrieve an IIterator from the map_base::First function, and use that to iterate through the elements in a map_base object.
...
#include <iostream>
using namespace winrt;
using namespace Windows::Foundation::Collections;
...
struct MyMap :
implements<MyMap, IMap<winrt::hstring, int>, IMapView<winrt::hstring, int>, IIterable<IKeyValuePair<winrt::hstring, int>>>,
winrt::map_base<MyMap, winrt::hstring, int>
{
auto& get_container() const noexcept
{
return m_values;
}
auto& get_container() noexcept
{
return m_values;
}
private:
std::map<winrt::hstring, int> m_values{
{ L"AliceBlue", 0xfff0f8ff }, { L"AntiqueWhite", 0xfffaebd7 }
};
};
...
IMap<winrt::hstring, int> map{ winrt::make<MyMap>() };
for (auto const& el : map)
{
std::wcout << el.Key().c_str() << L", " << std::hex << el.Value() << std::endl;
}
IIterator<IKeyValuePair<winrt::hstring, int>> it{ map.First() };
while (it.HasCurrent())
{
std::wcout << it.Current().Key().c_str() << L", " << std::hex << it.Current().Value() << std::endl;
it.MoveNext();
}
funzione map_base:: Clearmap_base::Clear function
Rimuove tutti gli elementi dall'oggetto map_base .Removes all elements from the map_base object.
SintassiSyntax
void Clear() noexcept;
funzione map_base:: Firstmap_base::First function
Recupera un IIterator che rappresenta il primo elemento nell'oggetto map_base .Retrieves an IIterator representing the first element in the map_base object.
SintassiSyntax
auto First();
Valore restituitoReturn value
IIterator che rappresenta il primo elemento nell'oggetto map_base .An IIterator representing the first element in the map_base object.
funzione map_base:: GetViewmap_base::GetView function
Recupera una visualizzazione non modificabile dell'oggetto map_base .Retrieves an immutable view of the map_base object.
SintassiSyntax
winrt::Windows::Foundation::Collections::IMapView<K, V> GetView() const;
Valore restituitoReturn value
IMapView contenente una visualizzazione non modificabile del map_base.An IMapView containing an immutable view of the map_base.
funzione map_base:: HasKeymap_base::HasKey function
Determina se la chiave specificata appartiene a un elemento nell'oggetto map_base .Determines whether the specified key belongs to an element in the map_base object.
SintassiSyntax
bool HasKey(K const& key) const noexcept;
ParametriParameters
key
la chiave da cercare.key
The key to look for.
Valore restituitoReturn value
true
se viene trovato un elemento contenente la chiave; in caso contrario, false
.true
if an element containing the key is found, otherwise false
.
funzione map_base:: Insertmap_base::Insert function
Inserisce o aggiorna un elemento nell'oggetto map_base .Inserts or updates an element in the map_base object.
SintassiSyntax
bool Insert(K const& key, V const& value);
ParametriParameters
key
la chiave associata all'elemento da inserire o aggiornare.key
The key associated with the element to insert or update.
value
il valore da inserire o sostituire.value
The value to insert or replace.
Valore restituitoReturn value
true
se è stato trovato e aggiornato un elemento con la chiave specificata. in caso contrario false
.true
if an element with the specified key was found and updated; otherwise false
.
funzione map_base:: Lookupmap_base::Lookup function
Cerca l'elemento identificato dalla chiave specificata e recupera il valore corrispondente.Looks up the element identified by the specified key, and retrieves the corresponding value.
SintassiSyntax
V Lookup(K const& key) const;
ParametriParameters
key
la chiave da cercare.key
The key to look up.
Valore restituitoReturn value
Valore corrispondente alla chiave ricercata, se trovata; in caso contrario, viene generata un'eccezione WinRT:: hresult_out_of_bounds .The value corresponding to the key being looked up if found, otherwise a winrt::hresult_out_of_bounds exception is thrown.
funzione map_base:: Removemap_base::Remove function
Rimuove un elemento dall'oggetto map_base .Removes an element from the map_base object.
SintassiSyntax
void Remove(K const& key);
ParametriParameters
key
la chiave associata all'elemento da rimuovere.key
The key associated with the element to remove.
funzione map_base:: sizemap_base::Size function
Recupera il numero di elementi nell'oggetto map_base .Retrieves the number of elements in the map_base object.
SintassiSyntax
uint32_t Size() const noexcept;
Valore restituitoReturn value
Valore che rappresenta il numero di elementi nell'oggetto map_base .A value representing the number of elements in the map_base object.