1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| #include <iostream>
#include <iomanip>
//~ #include <sqlite.h>
//~ #include <mysql/mysql.h>
using namespace std;
template <unsigned int x, unsigned int y, bool is_ordered = (x >= y)> //~ 一般情况下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> //~ 初始情况可能会是x<y
{
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 ()
{
cout<<static_gcd<24, 32>::value<<endl;
return 0;
} |
Filed under: 之语言特性,边走编程 By
dutor @
June 26th, 2009,
12 views

你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Be the first to comment on this entry.