I know the title is super confusing, but the following will make it clear.
I am using fmt library for formating and it has this precious feature.
auto res = fmt::format(FMT_STRING("{}{}"), 6, "Ed");
This is a compile time check on various things one of which is whether the number of arguments is equal to number of {} which need to be formatted.
In order not write this every time I decided to wrap this into utility:
template<typename Str, typename... Args>
auto format(Str&& str, Args&&... args)
{
return fmt::format(FMT_STRING(std::forward<Str>(str)), std::forward<Args>(args)...);
}
And willing to use this the same way:
utils::format("{}{}", 6, "Ed");
But now I am getting this error:
constexpr variable s must be initialized by a constant expression
FMT_CONSTEXPR auto s = basic_string_view(format_str)
where s
is some variable in the nested fmt::format
call.
Can someone help to fix this or tell me what I am missing?
The [mcve]
template<typename Str, typename... Args>
constexpr auto format(Str&& str, Args&&... args) {
constexpr auto&& s = std::forward<Str>(str);
}
int main () {
format("{}{}", 6, "Ed");
}