349 questions
7
votes
2
answers
421
views
Determine if a Type is formattable with given Format String at compile time
I am trying to come up with a way to determine, whether a given format string is valid for a given Type at compile time.
I was expecting for a simple concept to work:
template<typename T>
...
1
vote
1
answer
190
views
std::format output signed value when formatted as hexadecimal
// c++20
#include <iostream>
#include <format>
#include <winerror.h>
// typedef _Return_type_success_(return >= 0) long HRESULT;
// #define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
...
-1
votes
2
answers
107
views
Is there a way to "configure" formatting at compile time? [duplicate]
I have struct/class that formats numbers. I want to tune its formatting parameters how i like. And this means I "need"(could be not, if there's another much more clever way of doing it?):
&...
1
vote
1
answer
494
views
Clangd: call to consteval function 'fmt::basic_format_string<...>' is not a constant expression, but MSVC compiles it
I'm using spdlog with fmt::format_string to log messages, and I also want to capture the call location using std::source_location. My goal is to have a simple logging function like this:
Logger::Error(...
1
vote
0
answers
64
views
How to format types with suffices in libfmt? [duplicate]
I'm working as a side project on a strong physical type class template for C++. And now I'm having a problem in writing a formatter for {fmt} to display the value with the unit string properly.
Here ...
2
votes
1
answer
147
views
Is this a bug in implementation of std::format_to_n in g++ 13.2?
Consider the following snippet:
// #define USE_FMTLIB
#include <chrono>
#include <iostream>
#if defined(USE_FMTLIB)
#include <fmt/chrono.h>
#include <fmt/core.h>
#...
2
votes
0
answers
170
views
Missing std::/fmt::print(ln) that would not require a format string
When I write code, I frequently need to print some value to the terminal. I like the new C++23 <print> functionality with which I can write:
std::println("{}", value);
However, if I ...
3
votes
1
answer
238
views
How can I format a `std::chrono::year_month_day` with libfmt?
I am using gcc-13.3 with c++23 enabled.
I have the following code which uses std::format to format a std::chrono::year_month_day to a string:
#include <chrono>
#include <format>
#include &...
7
votes
1
answer
358
views
Is there a problem with fmt format_as in C++20?
I've got a simple code example that attempts to use a format_as() overload to format a custom type (an enum); it outputs a std::string found in a map.
From the link above, the compiler is configured ...
0
votes
1
answer
55
views
Usage of a defined template function converting an object to a string as a formatter for fmt::format
I’d like to make use of the existing to_string formatters in my code
struct A {};
struct B {};
template <typename T>
std::string to_string(const T&);
template <>
std::string ...
1
vote
3
answers
164
views
LOG macro that logs named variables
In my code I use printf-like LOG(const char* fmt, ...) macro. Under the hood it prints/logs to different output destinations (file, console, debugger output).
It's my own macro, so it does printf ...
8
votes
1
answer
586
views
Linking error in static linking with -gc-sections option
I was trying to produce a simple, fully statically linked binary so that it can easily run on distributions such as Alpine without having to install anything else.
In my use case, I'm only using a ...
2
votes
1
answer
136
views
Using nested dynamic arguments in custom fmt formatter
Considering the following working example:
#include<string>
#include<fmt/format.h>
class foo_type{};
template<> struct fmt::formatter<foo_type>{
private:
std::...
0
votes
2
answers
126
views
Provide custom fmt::formatter for protobuf message types
I have some protobuf message classes that I would like to be able to print using fmtlib. For example, I have a TaskStatus message where TaskStatus is derived from google::protobuf::Message. I am ...
2
votes
2
answers
416
views
How to define a generic fmt formatter for a template class?
I'm trying to define a reusable formatter for a class, let's say cv::Point_ from OpenCV. The code compiles fine on its own but when I use this formatter I get compilation errors. Here is the code:
...