C++17: std::char_traits<>::{compare,length} is constexpr.#2246
C++17: std::char_traits<>::{compare,length} is constexpr.#2246vitaut merged 1 commit intofmtlib:masterfrom
Conversation
There was a problem hiding this comment.
Just a few suggestions 😉
include/fmt/format.h
Outdated
| 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.
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.
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.
This change is for consistency across all uses of constexpr std::char_traits.
There was a problem hiding this comment.
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
| 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.
No need to use FMT_CONSTEXPR macro here, just constexpr would be enough.
| #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.
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.
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)