为何std::make_format_args要求非const引用?
关于std::make_format_args接受非const引用的疑问及代码报错问题
我查阅cppreference文档后,无法理解为何std::make_format_args()接受引用而非const引用?
我想要实现如下代码:
#include <format> template <class... Args> inline static std::string format(const std::string_view field, Args&&... args) { return std::vformat(field, std::make_format_args(std::forward<Args>(args)...)); }
我希望能在args中传入const std::string&,但std::make_format_args()似乎要求非const引用,因此出现如下错误:
A non-const reference may only be bound to an lvalue C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format(3713): note: see declaration of 'std::make_format_args' note: while trying to match the argument list '(_Ty, const std::string, _Ty, _Ty)'
更新
可通过在线编译器复现该错误,本地报错与上述一致
内容的提问来源于stack exchange,提问作者SpeakX
相关产品推荐
相关产品推荐

