Skip to content

Query about no throw registry iterators #645

Description

@aursulis

I have a question about wil::reg::key_heap_string_nothrow_iterator (and the bstr equivalent). Here's a snippet:

auto it = wil::reg::key_heap_string_nothrow_iterator((HKEY)0xdeadbeefULL); // create an iterator using an invalid handle
auto end_it = wil::reg::key_heap_string_nothrow_iterator();

for ([[maybe_unused]] const auto& key_data : wil::make_range(it, endit)) {
    std::cerr << "Did not expect this to happen!\n";
}
if (FAILED(it.last_error())) {
    std::cerr << "Error: " << std::hex << it.last_error() << "\n";
}

This prints:

Did not expect this to happen!
Error: 80070006

I adapted this code from the example in the source code here:

wil/include/wil/registry.h

Lines 203 to 211 in 1e810ec

// auto iterate_keys = wil::reg::key_heap_string_nothrow_iterator{hkey};
// for (const auto& key_data : wil::make_range(iterate_keys, wil::reg::key_heap_string_nothrow_iterator{}))
// {
// key_data.name.get(); // the PCWSTR of the enumerated key
// }
// if (FAILED(iterate_keys.last_error()))
// {
// // the HRESULT last_error() returns the registry error that prevented enumeration
// }

My question is whether the example demonstrates correct usage.

  • for nothrow iterators, should I check .last_error() before the loop? (the example doesn't, and arguably it makes the ergonomics unnecessarily worse)
  • is this perhaps a bug that the constructor doesn't go through m_data.make_end_iterator() on error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions