c++ - constexpr 使用 clang 编译 TensorFlow 时出错
问题描述
我正在尝试使用 clang 编译 tensorflow,并收到有关 constexpr 的以下错误
In file included from /tensorflow/tensorflow/lite/tools/make/downloads/absl/absl/time/clock.h:26:
/tensorflow/tensorflow/lite/tools/make/downloads/absl/absl/time/time.h:1404:55: error: constexpr function's 2nd parameter type 'std::ratio<60>' is not a literal type
constexpr Duration FromInt64(int64_t v, std::ratio<60>) {
~~~~~~~~~~~~~~^
/toolkit/include/usr/h/public/ratio:100:9: note: 'ratio<60, 1>' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors
struct ratio
^
这是相关的代码:
template <std::intmax_t N>
constexpr Duration FromInt64(int64_t v, std::ratio<1, N>) {
static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
// Subsecond ratios cannot overflow.
return MakeNormalizedDuration(
v / N, v % N * kTicksPerNanosecond * 1000 * 1000 * 1000 / N);
}
constexpr Duration FromInt64(int64_t v, std::ratio<60>) {
return (v <= (std::numeric_limits<int64_t>::max)() / 60 &&
v >= (std::numeric_limits<int64_t>::min)() / 60)
? MakeDuration(v * 60)
: v > 0 ? InfiniteDuration() : -InfiniteDuration();
}
谢谢,如果有人能指出我正确的方向
解决方案
它似乎在我的操场上工作
#include <ratio>
#include <iostream>
template <std::intmax_t N>
constexpr std::intmax_t FromInt64(int64_t v, std::ratio<1, N>) {
static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
return N;
}
constexpr std::intmax_t FromInt64(int64_t v, std::ratio<60>) {
return -100;
}
int main() {
auto a = FromInt64(5, std::ratio<1, 5>{});
std::cout << a << " "; // 5
auto b = FromInt64(5, std::ratio<60>{});
std::cout << b; // -100
}
推荐阅读
- python - 将.txt文件转换为csv时如何分隔列
- ios - SwiftUI 中的按钮大小和颜色
- git - 删除 .git/HEAD 文件后如何恢复 git 存储库
- postgresql - 带有spring-data-jdbc和postgres的springboot:时间戳上的尾随垃圾
- python - 客户端通过 send_file 命令调用服务器的 FLASK 端点时无法查看图像
- express - Using Vercel for frontend and Heroku for api
- amazon-web-services - Is there an easy way to allow incoming traffic from the AWS Console (in web-browser) in network security settings?
- r - How to add multiple polygons and layers in leaflet with a for loop?
- javascript - 在 connect() 生命周期回调中定义的 Stimulus.js 调用方法
- github - IntelliJ 将我从 Github 中注销