小编Los*_*ght的帖子

std :: enable_if使用非类型模板参数

你将如何在一个std::enable_if?中使用非类型模板参数比较?我无法弄清楚如何再次这样做.(我曾经有过这个工作,但是我丢失了代码,所以我无法回头看看,而且我找不到帖子,我找到了答案.)

提前感谢您对此主题的任何帮助.

template<int Width, int Height, typename T>
class Matrix{
    static
    typename std::enable_if<Width == Height, Matrix<Width, Height, T>>::type
    Identity(){
        Matrix ret;
        for (int y = 0; y < Width; y++){
            elements[y][y] = T(1);
        }
        return ret;
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:修复了注释中指出的缺失括号.

c++ templates c++11

5
推荐指数
1
解决办法
2405
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1