1 | /**************************************************************************\ |
---|
2 | |
---|
3 | MODULE: pair |
---|
4 | |
---|
5 | SUMMARY: |
---|
6 | |
---|
7 | Macros are defined providing template-like classes for pairs. |
---|
8 | |
---|
9 | The macro NTL_pair_decl(S,T,pair_S_T) declares a class pair_S_T whose |
---|
10 | implementation can be instatntiated with NTL_pair_impl(S,T,pair_S_T). It is |
---|
11 | presumed that the underlying types have a default constructor, a copy |
---|
12 | constructor, and assignment operator, and a destructor (this is |
---|
13 | normally the case for most types). |
---|
14 | |
---|
15 | If S and T support I/O operator << and >>, then pair_S_T can be made |
---|
16 | to support these operators as well using NTL_pair_io_decl(S,T,pair_S_T) and |
---|
17 | NTL_pair_io_impl(S,T,pair_S_T). |
---|
18 | |
---|
19 | The same goes for the equaltity operators == and != using |
---|
20 | NTL_pair_eq_decl(S,T,pair_S_T) and NTL_pair_eq_impl(S,T,pair_S,T). |
---|
21 | |
---|
22 | The decalaration |
---|
23 | |
---|
24 | pair_S_T p; |
---|
25 | |
---|
26 | creates a pair object using the default constructors for S and T. The |
---|
27 | member p.a is the first component (of type S) and the member p.b is |
---|
28 | the second component (of type T). |
---|
29 | |
---|
30 | |
---|
31 | \**************************************************************************/ |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | #include <NTL/tools.h> |
---|
36 | |
---|
37 | class pair_S_T { |
---|
38 | public: |
---|
39 | S a; |
---|
40 | T b; |
---|
41 | |
---|
42 | pair_S_T(); |
---|
43 | // default constructor...invokes default constructors for S and T |
---|
44 | |
---|
45 | pair_S_T(const pair_S_T& x); // copy |
---|
46 | |
---|
47 | pair_S_T& operator=(const pair_S_T& x); // assignment |
---|
48 | |
---|
49 | pair_S_T(const S& x, const T& y); // initialize with (x, y) |
---|
50 | |
---|
51 | ~pair_S_T(); |
---|
52 | // destructor...invokes destructors for S and T |
---|
53 | }; |
---|
54 | |
---|
55 | pair_S_T cons(const S& x, const T& y); |
---|
56 | // returns pair_S_T(x, y) |
---|
57 | |
---|
58 | |
---|
59 | /**************************************************************************\ |
---|
60 | |
---|
61 | Input/Output |
---|
62 | |
---|
63 | The I/O operators can be declared with NTL_pair_io_decl(S,T,pair_S_T), and |
---|
64 | implemented using NTL_pair_io_impl(S,T,pair_S_T). |
---|
65 | Elements are read and written using the underlying I/O |
---|
66 | operators << and >> for S and T. |
---|
67 | |
---|
68 | The I/O format for a pair_a_b is |
---|
69 | |
---|
70 | [a b] |
---|
71 | |
---|
72 | \**************************************************************************/ |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | istream& operator>>(istream&, pair_S_T&); |
---|
77 | ostream& operator<<(ostream&, const pair_S_T&); |
---|
78 | |
---|
79 | |
---|
80 | /**************************************************************************\ |
---|
81 | |
---|
82 | Equality Testing |
---|
83 | |
---|
84 | The equality testing operators == and != can be declared with |
---|
85 | NTL_pair_eq_decl(S,T,pair_S_T) and implemented with |
---|
86 | NTL_pair_eq_impl(S,T,pair_S,T). The tests are performed using |
---|
87 | the underlying operator == for S and T. |
---|
88 | |
---|
89 | \**************************************************************************/ |
---|
90 | |
---|
91 | |
---|
92 | long operator==(const pair_S_T& x, const pair_S_T& y); |
---|
93 | long operator!=(const pair_S_T& x, const pair_S_T& y); |
---|
94 | |
---|
95 | |
---|