Page List

Search on the blog

2010年8月29日日曜日

Invincible Macros for C++(3) : My Conclusion

After time-consuming research and hands-on experience, I've finally reached the conclusion.
This is "the best macros" I could come up with.
Of course seems like there exist plenty of rooms for improvement, but this is the best for now.
How does it feel like to you?

Please notice that "using namespace" phrase comes before the "typedef" part.
It is because you should explicitly write the namespace name before you use vectors.
Without this notation, you'd end up with compiler error.
It was not until I learned the fact that I found it was mistake to think typedef of "containers in STL" was impossible.
So write "using namespace std" before the "typedef" part.

(日本語)
C++のための最強のマクロ集(3)

長い長い研究と手探りの経験の結果、ついに結論に達した。
これが考えつく限り最強のマクロだ!
もちろん、改良の余地はあるが、今のところこれがベストである。
どうですかねー??

ここで、"using namespace"っていうフレーズが"typedef"の前にあることに気付いて下さい。
これは、vectorを使用する前に、名前空間を明示的に指定しないといけないからです。
この表記をつけなかったら、コンパイルエラーになります。
この事実に気付くまで、STLのコンテナのtypedefは不可能なんだと思いこんでいました(笑)
だから"using namespace std"って"typedef"の前にちゃんと書きましょう!



#include <algorithm>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>

using namespace std;

#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(x) ((x) < 0 ? - (x) : (x))
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define DISP(x) cout << #x << " : " << x << endl

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long int LL;

const double PI = acos(-1.0);

0 件のコメント:

コメントを投稿