Skip to content

Add printf.h for brace-style format string conversion and specifier h…#2

Open
penglei0 wants to merge 2 commits intov1.xfrom
feat-adaptor-for-cstyle-args-cpp-streams
Open

Add printf.h for brace-style format string conversion and specifier h…#2
penglei0 wants to merge 2 commits intov1.xfrom
feat-adaptor-for-cstyle-args-cpp-streams

Conversation

@penglei0
Copy link
Owner

…andling

Copilot AI review requested due to automatic review settings January 31, 2026 07:46
Copy link

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 pull request adds a new header file printf.h that provides compile-time conversion of printf-style format strings (e.g., %d, %.2f) to spdlog's brace-style format strings (e.g., {}). The implementation uses C++17 constexpr features to perform the conversion at compile time.

Changes:

  • Adds include/spdlog/printf.h with constexpr functions for format string conversion
  • Provides PRINTF and LOG_STREAM macros for convenient logging with printf-style syntax
  • Includes compile-time static assertions to validate the conversion logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +78 to +84
// Explicit 'constexpr' to lambda.
#define map_to_spdlog(str_literal) \
([]() constexpr { \
constexpr size_t _N = sizeof(str_literal); \
constexpr size_t _M = count_brace_size(str_literal); \
return to_brace_fmt<_N, _M>(str_literal); \
}())
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

Constexpr lambdas (line 80) are a C++17 feature, which conflicts with spdlog's C++11 minimum requirement. This will prevent compilation on C++11/C++14 compilers.

Suggested change
// Explicit 'constexpr' to lambda.
#define map_to_spdlog(str_literal) \
([]() constexpr { \
constexpr size_t _N = sizeof(str_literal); \
constexpr size_t _M = count_brace_size(str_literal); \
return to_brace_fmt<_N, _M>(str_literal); \
}())
// Map printf-style format string to spdlog-style at compile time, C++11-compatible.
#define map_to_spdlog(str_literal) \
(to_brace_fmt<sizeof(str_literal), count_brace_size(str_literal)>( \
(str_literal)))

Copilot uses AI. Check for mistakes.
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