Skip to content

Add std::format / std::formatter for win32 HKEY#157

Merged
EmJayGee merged 1 commit intomainfrom
micgrier/HKEY-formatter
Jan 20, 2026
Merged

Add std::format / std::formatter for win32 HKEY#157
EmJayGee merged 1 commit intomainfrom
micgrier/HKEY-formatter

Conversation

@EmJayGee
Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +17 to +34
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);
}

Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +7
#include <array>
#include <chrono>
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#include <array>
#include <chrono>

Copilot uses AI. Check for mistakes.
test_OVERLAPPED.cpp
test_Win32ErrorCode.cpp
)
)
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
)
)

Copilot uses AI. Check for mistakes.
@EmJayGee EmJayGee merged commit 2ef6788 into main Jan 20, 2026
11 checks passed
@EmJayGee EmJayGee deleted the micgrier/HKEY-formatter branch January 20, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants