This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
A base class from which you can derive to implement your own custom view, or span, of a contiguous sequence of elements in an associative collection. For more info, and code examples, see
Collections with C++/WinRT
.
Syntax
template <typename D, typename K, typename V, typename Version = winrt::impl::no_collection_version>
struct map_view_base : iterable_base<D, winrt::Windows::Foundation::Collections::IKeyValuePair<K, V>, Version>
Template parameters
typename D
Your derived type name.
typename K
The type of the keys in the collection that the map_view_base views, or spans.
typename V
The type of the values in the collection that the map_view_base views, or spans.
typename Version
A type that provides versioning policy and services to the collection.
Requirements
Minimum supported SDK: Windows SDK version 10.0.17763.0 (Windows 10, version 1809)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Member functions
Function
Description
map_view_base::First function
Retrieves an IIterator representing the first element viewed by the map_view_base object.
map_view_base::HasKey function
Determines whether the specified key belongs to an element viewed by the map_view_base object.
map_view_base::Lookup function
Looks up the element identified by the specified key, and retrieves the corresponding value.
map_view_base::Size function
Retrieves the number of elements viewed by the map_view_base object.
map_view_base::Split function
Splits the map view into two views.
Iterators
A map_view_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. Because of this, you can enumerate the elements viewed by a map_view_base object with a range-based for
statement.
You can also retrieve an IIterator from the map_view_base::First function, and use that to iterate through the elements viewed by a map_view_base object.
#include <iostream>
using namespace winrt;
using namespace Windows::Foundation::Collections;
struct MyMapView :
implements<MyMapView, IMapView<winrt::hstring, int>, IIterable<IKeyValuePair<winrt::hstring, int>>>,
winrt::map_view_base<MyMapView, winrt::hstring, int>
auto& get_container() const noexcept
return m_values;
private:
std::map<winrt::hstring, int> m_values{
{ L"AliceBlue", 0xfff0f8ff }, { L"AntiqueWhite", 0xfffaebd7 }
IMapView<winrt::hstring, int> view{ winrt::make<MyMapView>() };
for (auto const& el : view)
std::wcout << el.Key().c_str() << L", " << std::hex << el.Value() << std::endl;
IIterator<IKeyValuePair<winrt::hstring, int>> it{ view.First() };
while (it.HasCurrent())
std::wcout << it.Current().Key().c_str() << L", " << std::hex << it.Current().Value() << std::endl;
it.MoveNext();
map_view_base::First function
Retrieves an IIterator representing the first element viewed by the map_view_base object.
Syntax
auto First();
Return value
An IIterator representing the first element viewed by the map_view_base object.
map_view_base::HasKey function
Determines whether the specified key belongs to an element viewed by the map_view_base object.
Syntax
bool HasKey(K const& key) const noexcept;
Parameters
The key to look for.
Return value
true
if an element containing the key is found, otherwise false
.
map_view_base::Lookup function
Looks up the element identified by the specified key, and retrieves the corresponding value.
Syntax
V Lookup(K const& key) const;
Parameters
The key to look up.
Return value
The value corresponding to the key being looked up if found, otherwise a winrt::hresult_out_of_bounds exception is thrown.
map_view_base::Size function
Retrieves the number of elements viewed by the map_view_base object.
Syntax
uint32_t Size() const noexcept;
Return value
A value representing the number of elements viewed by the map_view_base object.
map_view_base::Split function
Splits the map view into two views.
Syntax
void Split(Windows::Foundation::Collections::IMapView<K, V>& first, Windows::Foundation::Collections::IMapView<K, V>& second) const noexcept;
Parameters
first
One half of the original map.
second
The second half of the original map.
See also
winrt namespace
winrt::single_threaded_map function template
Collections with C++/WinRT