Add std::format / std::formatter for win32 HKEY#157
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a std::formatter specialization for the Windows HKEY type, enabling it to be used with std::format. The formatter decodes well-known HKEY constants (like HKEY_CURRENT_USER) into their symbolic names and formats other HKEY values as "{hkey 0x[hex]}".
Changes:
- Added HKEY.h header implementing std::formatter<HKEY, CharT> specialization
- Added test_HKEY.cpp with unit tests covering HKEY formatting behavior
- Updated CMakeLists.txt files to include the new header and test files
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Windows/libraries/formatters/include/m/formatters/HKEY.h | Implements std::formatter specialization for HKEY with support for 10 named HKEY constants and generic hex formatting |
| src/Windows/libraries/formatters/test/test_HKEY.cpp | Adds unit tests for HKEY formatting with tests for named constants and default HKEY values |
| src/Windows/libraries/formatters/include/CMakeLists.txt | Registers HKEY.h in the formatters library header file set |
| src/Windows/libraries/formatters/test/CMakeLists.txt | Adds test_HKEY.cpp to the test executable build |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| TEST(HKEY, format_HKEY_CURRENT_USER) | ||
| { | ||
| auto s = std::format(L"{}", HKEY_CURRENT_USER); | ||
| EXPECT_EQ(s, L"HKEY_CURRENT_USER"s); | ||
| } | ||
|
|
||
| TEST(HKEY, format_HKEY_LOCAL_MACHINE) | ||
| { | ||
| auto s = std::format(L"{}", HKEY_LOCAL_MACHINE); | ||
| EXPECT_EQ(s, L"HKEY_LOCAL_MACHINE"s); | ||
| } | ||
|
|
||
| TEST(HKEY, format_default_hkey) | ||
| { | ||
| auto s = std::format(L"{}", HKEY{}); | ||
| EXPECT_EQ(s, L"{hkey 0x0}"s); | ||
| } | ||
|
|
There was a problem hiding this comment.
Test coverage is incomplete. The implementation handles 10 different named HKEY values (HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_PERFORMANCE_TEXT, HKEY_PERFORMANCE_NLSTEXT, HKEY_CURRENT_CONFIG, HKEY_DYN_DATA, HKEY_CURRENT_USER_LOCAL_SETTINGS) but only 2 are tested. Additionally, all tests use wide character formatting (L"{}") but narrow character formatting is also supported and should be tested.
| #include <array> | ||
| #include <chrono> |
There was a problem hiding this comment.
Unused includes detected. The headers <array> and <chrono> are included but not used in this file. These should be removed to reduce compilation dependencies and improve build times.
| #include <array> | |
| #include <chrono> |
| test_OVERLAPPED.cpp | ||
| test_Win32ErrorCode.cpp | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Inconsistent whitespace formatting. The closing parenthesis has a leading space which differs from the standard formatting convention. For consistency with typical CMake style, the closing parenthesis should either be on the same line as the last entry or on its own line without leading whitespace.
| ) | |
| ) |
Adds a std::formatter for the Windows.h HKEY type to decode the named HKEY values (HKEY_CURRENT_USER etc) and write the other cases as open brace, "hkey 0x", the hex representation of the handle value, and then the close brace.