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:
|
// 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?
I have a question about
wil::reg::key_heap_string_nothrow_iterator(and thebstrequivalent). Here's a snippet:This prints:
I adapted this code from the example in the source code here:
wil/include/wil/registry.h
Lines 203 to 211 in 1e810ec
My question is whether the example demonstrates correct usage.
.last_error()before the loop? (the example doesn't, and arguably it makes the ergonomics unnecessarily worse)m_data.make_end_iterator()on error?