Move size_ initialization to initializer list (#2529)

This commit is contained in:
Vladislav Shchapov 2021-10-03 05:20:33 +05:00 committed by GitHub
parent 012cc709d0
commit 0a985fd4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -433,13 +433,12 @@ template <typename Char> class basic_string_view {
*/ */
FMT_CONSTEXPR_CHAR_TRAITS FMT_CONSTEXPR_CHAR_TRAITS
FMT_INLINE FMT_INLINE
basic_string_view(const Char* s) : data_(s) { basic_string_view(const Char* s)
if (detail::const_check(std::is_same<Char, char>::value && : data_(s),
!detail::is_constant_evaluated(true))) size_(detail::const_check(std::is_same<Char, char>::value &&
size_ = std::strlen(reinterpret_cast<const char*>(s)); !detail::is_constant_evaluated(true))
else ? std::strlen(reinterpret_cast<const char*>(s))
size_ = std::char_traits<Char>::length(s); : std::char_traits<Char>::length(s)) {}
}
/** Constructs a string reference from a ``std::basic_string`` object. */ /** Constructs a string reference from a ``std::basic_string`` object. */
template <typename Traits, typename Alloc> template <typename Traits, typename Alloc>

View File

@ -2109,8 +2109,7 @@ FMT_CONSTEXPR_CHAR_TRAITS auto write(OutputIt out, const Char* value)
if (!value) { if (!value) {
throw_format_error("string pointer is null"); throw_format_error("string pointer is null");
} else { } else {
auto length = std::char_traits<Char>::length(value); out = write(out, basic_string_view<Char>(value));
out = write(out, basic_string_view<Char>(value, length));
} }
return out; return out;
} }