meta function,
boost mpl,
boost::common_factor库,
compile time:
template <unsigned
int x, unsigned
int y,
bool is_ordered = (x >= y)>
struct static_gcd
{
static int const value = static_gcd<y, x % y>
::value;
};
template <unsigned
int x, unsigned
int y>
struct static_gcd<x, y,
false>
{
static int const value = static_gcd<y, x>
::value;
};
template <unsigned
int x>
struct static_gcd<x,
0,
true>
{
static int const value =
x;
};
template <unsigned
int x>
struct static_gcd<x,
1,
true>
{
static int const value =
1;
};
int main()
{
std::cout << static_gcd<
24,
32>::value <<
'\n';
std::system("PAUSE");
}
转载于:https://www.cnblogs.com/prajna/archive/2013/02/26/2934410.html
相关资源:数据结构—成绩单生成器