Questions tagged «enable-if»

3
为什么我应该避免在函数签名中使用std :: enable_if
Scott Meyers发布了他的下一本书EC ++ 11的内容和状态。他写道,书中的一项可能是“避免std::enable_if使用函数签名”。 std::enable_if 可用作函数参数,返回类型或类模板或函数模板参数,以有条件地从重载解析中删除函数或类。 在此问题中,显示了所有三种解决方案。 作为功​​能参数: template<typename T> struct Check1 { template<typename U = T> U read(typename std::enable_if< std::is_same<U, int>::value >::type* = 0) { return 42; } template<typename U = T> U read(typename std::enable_if< std::is_same<U, double>::value >::type* = 0) { return 3.14; } }; 作为模板参数: template<typename T> struct …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.