diff --git a/include/fmt/core.h b/include/fmt/core.h index 12467eb6..14df3c1b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -472,11 +472,11 @@ struct compile_string {}; template struct is_compile_string : std::is_base_of {}; -template ::value>::type> -inline auto to_string_view(const S &s) -> basic_string_view { - typedef typename S::char_type char_type; - return basic_string_view{s.data(), s.size() - 1}; -} +template < + typename S, + typename Enable = typename std::enable_if::value>::type> +FMT_CONSTEXPR basic_string_view + to_string_view(const S &s) { return s; } template class basic_format_arg; diff --git a/include/fmt/format.h b/include/fmt/format.h index 4bf396e8..f05c5106 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2240,13 +2240,12 @@ FMT_CONSTEXPR bool check_format_string( return true; } -template -typename std::enable_if::value>::type - check_format_string(String format_str) { - typedef typename String::char_type char_type; - FMT_CONSTEXPR_DECL bool invalid_format = - internal::check_format_string( - basic_string_view(format_str.data(), format_str.size())); +template +typename std::enable_if::value>::type + check_format_string(S format_str) { + typedef typename S::char_type char_t; + FMT_CONSTEXPR_DECL bool invalid_format = internal::check_format_string< + char_t, internal::error_handler, Args...>(to_string_view(format_str)); (void)invalid_format; } @@ -3649,14 +3648,15 @@ operator"" _a(const wchar_t *s, std::size_t) { return {s}; } FMT_END_NAMESPACE #define FMT_STRING(s) [] { \ - typedef typename std::decay::type pointer; \ - struct S : fmt::compile_string { \ - typedef typename std::remove_cv::type>::type char_type;\ - static FMT_CONSTEXPR pointer data() { return s; } \ - static FMT_CONSTEXPR size_t size() { return sizeof(s) / sizeof(char_type); } \ - explicit operator fmt::basic_string_view() const { return s; } \ + typedef typename std::remove_cv::type>::type>::type ct; \ + struct str : fmt::compile_string { \ + typedef ct char_type; \ + FMT_CONSTEXPR operator fmt::basic_string_view() const { \ + return {s, sizeof(s) / sizeof(ct) - 1}; \ + } \ }; \ - return S{}; \ + return str{}; \ }() #if defined(FMT_STRING_ALIAS) && FMT_STRING_ALIAS