use const_check

This commit is contained in:
Elliot Haisley 2021-04-05 10:14:26 -04:00
parent df6827edb9
commit 7b5ef2dfe9

View File

@ -98,13 +98,6 @@
# define FMT_CONSTEXPR_DECL # define FMT_CONSTEXPR_DECL
#endif #endif
// C++17's char_traits::length() is constexpr.
#if __cplusplus >= 201703L
# define FMT_CONSTEXPR_CHAR_TRAITS_LENGTH FMT_CONSTEXPR
#else
# define FMT_CONSTEXPR_CHAR_TRAITS_LENGTH
#endif
#ifndef FMT_OVERRIDE #ifndef FMT_OVERRIDE
# if FMT_HAS_FEATURE(cxx_override_control) || \ # if FMT_HAS_FEATURE(cxx_override_control) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
@ -399,8 +392,12 @@ template <typename Char> class basic_string_view {
the size with ``std::char_traits<Char>::length``. the size with ``std::char_traits<Char>::length``.
\endrst \endrst
*/ */
FMT_CONSTEXPR_CHAR_TRAITS_LENGTH FMT_INLINE basic_string_view(const Char* s) : data_(s) { // C++17's char_traits::length() is constexpr.
if FMT_CONSTEXPR_CHAR_TRAITS_LENGTH (std::is_same<Char, char>::value && !detail::is_constant_evaluated()) #if __cplusplus >= 201703L
constexpr
#endif
FMT_INLINE basic_string_view(const Char* s) : data_(s) {
if (detail::const_check(std::is_same<Char, char>::value && !detail::is_constant_evaluated()))
size_ = std::strlen(reinterpret_cast<const char*>(s)); size_ = std::strlen(reinterpret_cast<const char*>(s));
else else
size_ = std::char_traits<Char>::length(s); size_ = std::char_traits<Char>::length(s);