-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding a default format for std::chrono::time_point<std::chrono::syst… #2345
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was presuming basic_string_view
has a constructor that takes in const char (&)[N]
.
I look up the source today. It turns out there isn't one.
I accidently merged the upstream commits. Now I reset to 12aacc2 |
fixed, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Minor comments inline, otherwise LGTM.
Note that in principle, one can use something like |
I don't think it'll work in this particular case because we need a static string and |
It could be made a |
Good idea, let's do that instead of my earlier suggestion. |
But using
|
Inline variables are introduced in C++17, before C++17 we seem to have to generate the symbol somewhere. GCC and Clang add supports for inline variables under C++17 as an extension. It seems a failure on MSVC and on older versions of GCC/Clang. |
Line 842 in 36c2948
Lines 148 to 149 in 36c2948
|
Does this mean I need to create a This seems to be a huge change beyond my scope. |
Can't we use here something like: template<typename A, typename B>
class formatter<A, B> {
static constexpr auto var = { /* initializer here */ };
};
template <typename A, typename B> constexpr B formatter<A, B>::var[]; For me, it's a big question why this code: Lines 1686 to 1691 in 36c2948
does not require any out-of-class definitions. |
Let's have a try. |
You only need a definition if something is "ODR used". Reading a constant integer is not an ODR use, but some part of the code that deals with string literals seems to ODR use the format spec.
This should definitely work. |
Oops, I find my implementation cannot handle compile time string correctly for C++17/20. The format will be parsed empty in fmt::print(FMT_COMPILE("{}"), std::chrono::system_clock::now()); But it works correctly in fmt::print(FMT_COMPILE("{:}"), std::chrono::system_clock::now()); I don't know what's behind the scene, but I guess the So I move the assignment I tested it on my g++-11 with C++11/14/17/20 standard. |
Thank you! |
For #2319, I add a defalut spec when the format is
{}
.Here I use function overload to avoid
if constexpr
or different template specializations. If you want to support more char types, you can provide with more overload resolutions, or use some template metaprogramming techniques (to restrictsizeof(Char)
).