下面这段代码取自folly,使用模板技术在编译时判断一个数字是否大于另一个,在GCC4.8.2下面编译没有问题,但是在Visual C++ 2013下面却无法通过,这是为什么?
#include
#include
#include
template
bool greater_than_impl(
typename std::enable_if<
(rhs <= std::numeric_limits::max()
&& rhs >= std::numeric_limits::min()),
LHS
>::type const lhs
) {
return lhs > rhs;
}
template
bool greater_than_impl(
typename std::enable_if<
(rhs > std::numeric_limits::max()),
LHS
> ::type const
) {
return false;
}
template
bool greater_than_impl(
typename std::enable_if <
(rhs < std::numeric_limits::min()),
LHS
>::type const
) {
return true;
}
template
bool greater_than(LHS const lhs) {
return greater_than_impl<
RHS, rhs, typename std::remove_reference::type
>(lhs);
}
int main(int argc, char* argv[])
{
auto v = greater_than(0u);
std::cout << v << endl;
return 0;
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证高级PHP讲师