Add printf.h for brace-style format string conversion and specifier h…#2
Open
Add printf.h for brace-style format string conversion and specifier h…#2
Conversation
There was a problem hiding this comment.
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.hwith constexpr functions for format string conversion - Provides
PRINTFandLOG_STREAMmacros 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); \ | ||
| }()) |
There was a problem hiding this comment.
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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…andling