【发布时间】:2022-01-01 06:04:38
【问题描述】:
我有一辆马车program。逻辑是废话,只是一个玩具例子。
#include <ranges>
#include <iostream>
#include <fmt/format.h>
#include <fmt/ranges.h>
template<typename T>
constexpr bool size_is_4(){
return sizeof(T)==4;
}
int main() {
std::cout << fmt::format("float size is 4 bytes : {}\n", size_is_4<float>);
std::cout << fmt::format("double size is 4 bytes : {}\n", size_is_4<double>);
}
输出是
浮点大小为 4 个字节:true
双倍大小为 4 个字节:true
问题是我将函数指针传递给fmt::format 并将其打印为布尔值。修复很简单,直接调用函数就好了,不知道有没有办法捕捉到这样的bug。
由于函数返回bool,它实际上看起来是合理的输出。
【问题讨论】: