diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 5e19ac6b..52961389 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -19,15 +19,7 @@ FMT_BEGIN_NAMESPACE -template struct formatting_base { - template - FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); - } -}; - -template -struct formatting_range : formatting_base { +template struct formatting_range { #ifdef FMT_DEPRECATED_BRACED_RANGES Char prefix = '{'; Char postfix = '}'; @@ -35,12 +27,21 @@ struct formatting_range : formatting_base { Char prefix = '['; Char postfix = ']'; #endif + + template + FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } }; -template -struct formatting_tuple : formatting_base { +template struct formatting_tuple { Char prefix = '('; Char postfix = ')'; + + template + FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } }; namespace detail { @@ -362,50 +363,52 @@ struct formatter< } }; -template struct tuple_arg_join : detail::view { +template struct tuple_join_view : detail::view { const std::tuple& tuple; basic_string_view sep; - tuple_arg_join(const std::tuple& t, basic_string_view s) + tuple_join_view(const std::tuple& t, basic_string_view s) : tuple(t), sep{s} {} }; template -struct formatter, Char> { +using tuple_arg_join = tuple_join_view; + +template +struct formatter, Char> { template FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { return ctx.begin(); } template - typename FormatContext::iterator format( - const tuple_arg_join& value, FormatContext& ctx) { + auto format(const tuple_join_view& value, FormatContext& ctx) -> + typename FormatContext::iterator { return format(value, ctx, detail::make_index_sequence{}); } private: template - typename FormatContext::iterator format( - const tuple_arg_join& value, FormatContext& ctx, - detail::index_sequence) { + auto format(const tuple_join_view& value, FormatContext& ctx, + detail::index_sequence) -> + typename FormatContext::iterator { return format_args(value, ctx, std::get(value.tuple)...); } template - typename FormatContext::iterator format_args( - const tuple_arg_join&, FormatContext& ctx) { + auto format_args(const tuple_join_view&, FormatContext& ctx) -> + typename FormatContext::iterator { // NOTE: for compilers that support C++17, this empty function instantiation // can be replaced with a constexpr branch in the variadic overload. return ctx.out(); } template - typename FormatContext::iterator format_args( - const tuple_arg_join& value, FormatContext& ctx, - const Arg& arg, const Args&... args) { + auto format_args(const tuple_join_view& value, FormatContext& ctx, + const Arg& arg, const Args&... args) -> + typename FormatContext::iterator { using base = formatter::type, Char>; - auto out = ctx.out(); - out = base{}.format(arg, ctx); + auto out = base().format(arg, ctx); if (sizeof...(Args) > 0) { out = std::copy(value.sep.begin(), value.sep.end(), out); ctx.advance_to(out); @@ -429,14 +432,15 @@ FMT_MODULE_EXPORT_BEGIN \endrst */ template -FMT_CONSTEXPR tuple_arg_join join(const std::tuple& tuple, - string_view sep) { +FMT_CONSTEXPR auto join(const std::tuple& tuple, string_view sep) + -> tuple_join_view { return {tuple, sep}; } template -FMT_CONSTEXPR tuple_arg_join join( - const std::tuple& tuple, basic_string_view sep) { +FMT_CONSTEXPR auto join(const std::tuple& tuple, + basic_string_view sep) + -> tuple_join_view { return {tuple, sep}; } @@ -452,8 +456,8 @@ FMT_CONSTEXPR tuple_arg_join join( \endrst */ template -join_view join(std::initializer_list list, - string_view sep) { +auto join(std::initializer_list list, string_view sep) + -> join_view { return join(std::begin(list), std::end(list), sep); } diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 4fae7999..f316ad17 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -9,6 +9,7 @@ #define FMT_WCHAR_H_ #include +#include #include "format.h" @@ -75,9 +76,10 @@ auto join(std::initializer_list list, wstring_view sep) template , FMT_ENABLE_IF(detail::is_locale::value&& detail::is_exotic_char::value)> -inline std::basic_string vformat( +inline auto vformat( const Locale& loc, const S& format_str, - basic_format_args>> args) { + basic_format_args>> args) + -> std::basic_string { return detail::vformat(loc, to_string_view(format_str), args); } @@ -85,8 +87,8 @@ template , FMT_ENABLE_IF(detail::is_locale::value&& detail::is_exotic_char::value)> -inline std::basic_string format(const Locale& loc, const S& format_str, - Args&&... args) { +inline auto format(const Locale& loc, const S& format_str, Args&&... args) + -> std::basic_string { return detail::vformat(loc, to_string_view(format_str), fmt::make_args_checked(format_str, args...)); } @@ -126,9 +128,9 @@ template ::value&& detail::is_locale::value&& detail::is_exotic_char::value)> -inline OutputIt vformat_to( +inline auto vformat_to( OutputIt out, const Locale& loc, const S& format_str, - basic_format_args>> args) { + basic_format_args>> args) -> OutputIt { auto&& buf = detail::get_buffer(out); vformat_to(buf, to_string_view(format_str), args, detail::locale_ref(loc)); return detail::get_iterator(buf); @@ -202,7 +204,7 @@ template void print(wformat_string fmt, T&&... args) { /** Converts *value* to ``std::wstring`` using the default format for type *T*. */ -template inline std::wstring to_wstring(const T& value) { +template inline auto to_wstring(const T& value) -> std::wstring { return format(FMT_STRING(L"{}"), value); } FMT_MODULE_EXPORT_END