Simplify implementation of operator""_cf (#4349)

This commit is contained in:
Victor Chernyakin
2025-02-14 03:02:09 -07:00
committed by GitHub
parent 0ca42e836e
commit 94ab51cb8c

View File

@ -41,16 +41,6 @@ namespace detail {
# define FMT_COMPILE(s) FMT_STRING(s) # define FMT_COMPILE(s) FMT_STRING(s)
#endif #endif
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
template <typename Char, size_t N, fmt::detail::fixed_string<Char, N> Str>
struct udl_compiled_string : compiled_string {
using char_type = Char;
constexpr explicit operator basic_string_view<char_type>() const {
return {Str.data, N - 1};
}
};
#endif
template <typename T, typename... Tail> template <typename T, typename... Tail>
auto first(const T& value, const Tail&...) -> const T& { auto first(const T& value, const Tail&...) -> const T& {
return value; return value;
@ -538,9 +528,7 @@ void print(const S& fmt, const Args&... args) {
#if FMT_USE_NONTYPE_TEMPLATE_ARGS #if FMT_USE_NONTYPE_TEMPLATE_ARGS
inline namespace literals { inline namespace literals {
template <detail::fixed_string Str> constexpr auto operator""_cf() { template <detail::fixed_string Str> constexpr auto operator""_cf() {
using char_t = remove_cvref_t<decltype(Str.data[0])>; return FMT_COMPILE(Str.data);
return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
Str>();
} }
} // namespace literals } // namespace literals
#endif #endif