gpt4 book ai didi

c++ - {fmt} : Compile-time string format check doesn't work

转载 作者:搜寻专家 更新时间:2023-10-31 02:02:16 24 4
gpt4 key购买 nike

我正在尝试使用 fmt 5.3.0(仅 header )在编译时检查格式字符串。

$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
#define FMT_HEADER_ONLY
#define FMT_STRING_ALIAS 1

#include <fmt/format.h>

int main(){
std::string s = format(fmt("{2}"), 42);
return 0;
}

$ g++ -I../include -std=c++11 test.cpp...没有

根据 fmt 自述文件,这应该会产生错误 ( https://github.com/fmtlib/fmt )。

最佳答案

编译时检查需要足够的 constexpr 支持。用g++ 5.4 and c++ 11不会有编译时检查,但有 g++ 6.1 and c++ 14将有。另见 FMT_USE_CONSTEXPR 的定义.

关于c++ - {fmt} : Compile-time string format check doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57583184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com