【发布时间】:2021-08-14 19:16:04
【问题描述】:
我正在查看下面来自std::chrono 的代码,但我不明白_Rep(min)() 的语法。
我知道_Rep 是返回类型,min 必须是方法名,但是:
- 写成
_Rep(min)()和_Rep min()有什么区别? - 而且,为什么
zero不这样做?
template <class _Rep>
struct duration_values { // gets arithmetic properties of a type
_NODISCARD static constexpr _Rep zero() noexcept {
// get zero value
return _Rep(0);
}
_NODISCARD static constexpr _Rep(min)() noexcept {
// get smallest value
return numeric_limits<_Rep>::lowest();
}
_NODISCARD static constexpr _Rep(max)() noexcept {
// get largest value
return (numeric_limits<_Rep>::max)();
}
};
我在numeric_limits 中看到了相同的构造:
_NODISCARD static constexpr _Ty(min)() noexcept {
return _Ty();
}
_NODISCARD static constexpr _Ty(max)() noexcept {
return _Ty();
}
更多信息,以防万一:
- 我正在使用 Microsoft Visual Studio Professional 2022 预览版(64 位),版本 17.0.0,预览版 1.1。
- 我的
chrono文件位于 Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.29.30130\include 下。
还有一个我一直在玩的在线小例子:https://godbolt.org/z/E5nW7x8vW
【问题讨论】: