c++11 - C++ 11 enable_if的重载问题
PHP中文网
PHP中文网 2017-04-17 11:18:22
[C++讨论组]

下面这段代码取自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;
}
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号