in cppwinrt/code_writers.h [1296:1480]
static void write_consume_extensions(writer& w, TypeDef const& type)
{
type_name type_name(type);
if (type_name == "Windows.UI.Xaml.Interop.IBindableIterator")
{
w.write(R"(
auto& operator++()
{
if (!MoveNext())
{
static_cast<D&>(*this) = nullptr;
}
return static_cast<D&>(*this);
}
auto operator*() const
{
return Current();
}
void operator++(int)
{
++(*this);
}
)");
}
else if (type_name == "Windows.Storage.Streams.IBuffer")
{
w.write(R"(
auto data() const
{
uint8_t* data{};
static_cast<D const&>(*this).template as<IBufferByteAccess>()->Buffer(&data);
return data;
}
)");
}
else if (type_name == "Windows.Foundation.IMemoryBufferReference")
{
w.write(R"(
auto data() const
{
uint8_t* data{};
uint32_t capacity{};
check_hresult(static_cast<D const&>(*this).template as<IMemoryBufferByteAccess>()->GetBuffer(&data, &capacity));
return data;
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IIterator`1")
{
w.write(R"(
auto& operator++()
{
if (!MoveNext())
{
static_cast<D&>(*this) = nullptr;
}
return static_cast<D&>(*this);
}
T operator*() const
{
return Current();
}
void operator++(int)
{
++(*this);
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IKeyValuePair`2")
{
w.write(R"(
bool operator==(Windows::Foundation::Collections::IKeyValuePair<K, V> const& other) const
{
return Key() == other.Key() && Value() == other.Value();
}
bool operator!=(Windows::Foundation::Collections::IKeyValuePair<K, V> const& other) const
{
return !(*this == other);
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IMapView`2")
{
w.write(R"(
auto TryLookup(param_type<K> const& key) const
{
if constexpr (std::is_base_of_v<Windows::Foundation::IUnknown, V>)
{
V result{ nullptr };
impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMapView<K, V>)->Lookup(get_abi(key), put_abi(result)));
return result;
}
else
{
std::optional<V> result;
V value{ empty_value<V>() };
if (0 == impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMapView<K, V>)->Lookup(get_abi(key), put_abi(value))))
{
result = std::move(value);
}
return result;
}
}
)");
}
else if (type_name == "Windows.Foundation.Collections.IMap`2")
{
w.write(R"(
auto TryLookup(param_type<K> const& key) const
{
if constexpr (std::is_base_of_v<Windows::Foundation::IUnknown, V>)
{
V result{ nullptr };
impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(result)));
return result;
}
else
{
std::optional<V> result;
V value{ empty_value<V>() };
if (0 == impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(value))))
{
result = std::move(value);
}
return result;
}
}
auto TryRemove(param_type<K> const& key) const
{
return 0 == impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMap<K, V>)->Remove(get_abi(key)));
}
)");
}
else if (type_name == "Windows.Foundation.IAsyncAction")
{
w.write(R"( auto get() const;
auto wait_for(Windows::Foundation::TimeSpan const& timeout) const;
)");
}
else if (type_name == "Windows.Foundation.IAsyncOperation`1")
{
w.write(R"( auto get() const;
auto wait_for(Windows::Foundation::TimeSpan const& timeout) const;
)");
}
else if (type_name == "Windows.Foundation.IAsyncActionWithProgress`1")
{
w.write(R"( auto get() const;
auto wait_for(Windows::Foundation::TimeSpan const& timeout) const;
)");
}
else if (type_name == "Windows.Foundation.IAsyncOperationWithProgress`2")
{
w.write(R"( auto get() const;
auto wait_for(Windows::Foundation::TimeSpan const& timeout) const;
)");
}
else if (type_name == "Windows.Foundation.Collections.IIterable`1")
{
w.write(R"(
auto begin() const;
auto end() const;
)");
}
else if (type_name == "Windows.UI.Xaml.Interop.IBindableIterable")
{
w.write(R"(
auto begin() const;
auto end() const;
)");
}
}