小编Jos*_*rez的帖子

为什么在year_month类中使用模板?

在 MSVC chrono 实现中我看到以下代码

    _EXPORT_STD template <int = 0>
_NODISCARD constexpr year_month operator+(const year_month& _Left, const months& _Right) noexcept {
    const auto _Mo  = static_cast<long long>(static_cast<unsigned int>(_Left.month())) + (_Right.count() - 1);
    const auto _Div = (_Mo >= 0 ? _Mo : _Mo - 11) / 12;
    return year_month{_Left.year() + years{_Div}, month{static_cast<unsigned int>(_Mo - _Div * 12 + 1)}};
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下为什么它使用带有未命名参数的模板吗?

c++ c++-chrono

22
推荐指数
1
解决办法
1440
查看次数

标签 统计

c++ ×1

c++-chrono ×1