From 588bdb5404dfe976f9195d1d94ac44d8df796ef9 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 15 May 2021 06:28:20 -0700 Subject: [PATCH] Simplify get_arg_index_by_name --- include/fmt/core.h | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 4b5236f6..399b70e7 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2444,28 +2444,22 @@ constexpr int get_arg_index_by_name(basic_string_view name) { if constexpr (detail::is_statically_named_arg()) { if (name == T::name) return N; } - if constexpr (sizeof...(Args) == 0) { - return invalid_arg_index; - } else { + if constexpr (sizeof...(Args) > 0) return get_arg_index_by_name(name); - } -} - -template -constexpr int get_arg_index_by_name(basic_string_view name) { - if constexpr (sizeof...(Args) == 0) { - return invalid_arg_index; - } else { - return get_arg_index_by_name<0, Args...>(name); - } -} -#else -template -constexpr int get_arg_index_by_name(basic_string_view) { return invalid_arg_index; } #endif +template +FMT_CONSTEXPR int get_arg_index_by_name(basic_string_view name) { +#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS + if constexpr (sizeof...(Args) > 0) + return get_arg_index_by_name<0, Args...>(name); +#endif + (void)name; + return invalid_arg_index; +} + template class format_string_checker { public: