#include <iostream>
//abs
template <long x, typename enabled=void>
struct tabs { const static long value = x; };
template <long x>
struct tabs<x,typename enable_if_c<(x < 0)>::type> { const static long value = -x; };
//max
template <long x, long y, typename enabled=void>
struct tmax { const static long value = x; };
template <long x, long y>
struct tmax<x,y,typename enable_if_c<(y > x)>::type> { const static long value = y; };
//min
template <long x, long y, typename enabled=void>
struct tmin { const static long value = x; };
template <long x, long y>
struct tmin<x,y,typename enable_if_c<(y < x)>::type> { const static long value = y; };
int main() {
tabs<-4>::value == 4;
tabs<4>::value == 4;
tmax<4,7>::value == 7
tmin<4,7>::value == 4
}
来源:CSDN
作者:哈哈哈哈哈哈哈哈哈...........
链接:https://blog.csdn.net/u011144881/article/details/104587777