1 | |
---|
2 | #ifndef NTL_pair__H |
---|
3 | #define NTL_pair__H |
---|
4 | |
---|
5 | #include <NTL/tools.h> |
---|
6 | |
---|
7 | #define NTL_pair_decl(S,T,pair_S_T) \ |
---|
8 | class pair_S_T { \ |
---|
9 | public: \ |
---|
10 | S a; \ |
---|
11 | T b; \ |
---|
12 | \ |
---|
13 | pair_S_T() { } \ |
---|
14 | pair_S_T(const pair_S_T& l__x) : a(l__x.a), b(l__x.b) { } \ |
---|
15 | pair_S_T& operator=(const pair_S_T& l__x) { a = l__x.a; b = l__x.b; return *this; } \ |
---|
16 | pair_S_T(const S& l__x, const T& l__y) : a(l__x), b(l__y) { } \ |
---|
17 | ~pair_S_T() { } \ |
---|
18 | }; \ |
---|
19 | \ |
---|
20 | inline pair_S_T cons(const S& l__x, const T& l__y) { return pair_S_T(l__x, l__y); } \ |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | #define NTL_pair_io_decl(S,T,pair_S_T) \ |
---|
26 | NTL_SNS istream& operator>>(NTL_SNS istream&, pair_S_T&); \ |
---|
27 | \ |
---|
28 | NTL_SNS ostream& operator<<(NTL_SNS ostream&, const pair_S_T&); \ |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | #define NTL_pair_eq_decl(S,T,pair_S_T) \ |
---|
33 | inline long operator==(const pair_S_T& l__x, const pair_S_T& l__y) \ |
---|
34 | { return l__x.a == l__y.a && l__x.b == l__y.b; } \ |
---|
35 | inline long operator!=(const pair_S_T& l__x, const pair_S_T& l__y) \ |
---|
36 | { return !(l__x == l__y); } \ |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | // For compatability... |
---|
41 | #define NTL_pair_impl(S,T,pair_S_T) |
---|
42 | |
---|
43 | |
---|
44 | #define NTL_pair_io_impl(S,T,pair_S_T) \ |
---|
45 | NTL_SNS istream& operator>>(NTL_SNS istream& l__s, pair_S_T& l__x) \ |
---|
46 | { \ |
---|
47 | long l__c; \ |
---|
48 | \ |
---|
49 | if (!l__s) NTL_NNS Error("bad pair input"); \ |
---|
50 | \ |
---|
51 | l__c = l__s.peek(); \ |
---|
52 | while (l__c == ' ' || l__c == '\n' || l__c == '\t') { \ |
---|
53 | l__s.get(); \ |
---|
54 | l__c = l__s.peek(); \ |
---|
55 | } \ |
---|
56 | \ |
---|
57 | if (l__c != '[') \ |
---|
58 | NTL_NNS Error("bad pair input"); \ |
---|
59 | \ |
---|
60 | l__s.get(); \ |
---|
61 | \ |
---|
62 | if (!(l__s >> l__x.a)) \ |
---|
63 | NTL_NNS Error("bad pair input"); \ |
---|
64 | if (!(l__s >> l__x.b)) \ |
---|
65 | NTL_NNS Error("bad pair input"); \ |
---|
66 | \ |
---|
67 | l__c = l__s.peek(); \ |
---|
68 | while (l__c == ' ' || l__c == '\n' || l__c == '\t') { \ |
---|
69 | l__s.get(); \ |
---|
70 | l__c = l__s.peek(); \ |
---|
71 | } \ |
---|
72 | \ |
---|
73 | if (l__c != ']') \ |
---|
74 | NTL_NNS Error("bad pair input"); \ |
---|
75 | \ |
---|
76 | l__s.get(); \ |
---|
77 | \ |
---|
78 | return l__s; \ |
---|
79 | } \ |
---|
80 | \ |
---|
81 | NTL_SNS ostream& operator<<(NTL_SNS ostream& l__s, const pair_S_T& l__x) \ |
---|
82 | { \ |
---|
83 | return l__s << "[" << l__x.a << " " << l__x.b << "]"; \ |
---|
84 | } \ |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | // For compatability... |
---|
89 | #define NTL_pair_eq_impl(S,T,pair_S_T) |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | #endif |
---|