-
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
C++17: std::char_traits<>::{compare,length} is constexpr. #2246
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.
Just a few suggestions 😉
include/fmt/format.h
Outdated
@@ -2149,7 +2149,10 @@ FMT_CONSTEXPR OutputIt write(OutputIt out, Char value) { | |||
} | |||
|
|||
template <typename Char, typename OutputIt> | |||
FMT_CONSTEXPR OutputIt write(OutputIt out, const Char* value) { | |||
#if FMT_HAS_CONSTEXPR_CHAR_TRAITS // C++17's char_traits::length() is constexpr. | |||
FMT_CONSTEXPR |
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.
No need to use FMT_CONSTEXPR
macro here, just constexpr
would be enough.
include/fmt/core.h
Outdated
#if FMT_HAS_CONSTEXPR_CHAR_TRAITS // C++17's char_traits::compare() is constexpr. | ||
constexpr | ||
#endif |
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.
No need to make this function constexpr
in this PR, I think.
This can be done as needed in the following PRs.
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.
This change is for consistency across all uses of constexpr std::char_traits
.
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.
All I'm just saying is that this function is non-constexpr
currently, unlike basic_string_view
constructor or write(const Char* value)
, so there is no need to make it constexpr
in this PR.
include/fmt/color.h
Outdated
@@ -432,7 +432,10 @@ template <typename Char> struct ansi_color_escape { | |||
FMT_CONSTEXPR operator const Char*() const FMT_NOEXCEPT { return buffer; } | |||
|
|||
FMT_CONSTEXPR const Char* begin() const FMT_NOEXCEPT { return buffer; } | |||
FMT_CONSTEXPR const Char* end() const FMT_NOEXCEPT { | |||
#if FMT_HAS_CONSTEXPR_CHAR_TRAITS // C++17's char_traits::length() is constexpr. | |||
FMT_CONSTEXPR |
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.
No need to use FMT_CONSTEXPR
macro here, just constexpr
would be enough.
include/fmt/core.h
Outdated
#if __cplusplus >= 201703L | ||
# ifndef __GLIBCXX__ | ||
# define FMT_HAS_CONSTEXPR_CHAR_TRAITS 1 | ||
# elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 7 | ||
# define FMT_HAS_CONSTEXPR_CHAR_TRAITS 1 | ||
# endif | ||
#endif | ||
#ifndef FMT_HAS_CONSTEXPR_CHAR_TRAITS | ||
# define FMT_HAS_CONSTEXPR_CHAR_TRAITS 0 | ||
#endif |
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 suggest you comment on this check because it's not a really straightforward one 🙂
c67230c
to
8327f37
Compare
8327f37
to
2e049b4
Compare
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. In general looks good but let's replace FMT_HAS_CONSTEXPR_CHAR_TRAITS
with FMT_CONSTEXPR_CHAR_TRAITS
that expands to constexpr
or nothing depending on availability of constexpr char traits. This will make usage cleaner which is important because we plan to use this macro in multiple places.
Actually looking at the latest diff, you already made the suggested change =). GitHub confusingly shows the old code in Conversation. |
It looks like there is a problem that no one can ever expect: https://godbolt.org/z/Ps7q8dGME |
Oh!!! I can make pull request tonight. Fix:
to:
New comment:
|
@alexezeder, Can you make a pull request? |
Actually I already somehow fixed this with 77258f6: - #if __cplusplus >= 201703L
+ #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) Looking at your proposal, probably it's not enough since you have an additional
Of course I can, but it's not needed right now because, as I said, I make it work for my PR. Feel free to make PR at your convenience. |
|
Discussion: #2243 (comment)