Skip to content

Commit 678b113

Browse files
pair header: constructors, getter, = and << operator
1 parent e6bfa68 commit 678b113

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

cpp4j/pair.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef PAIR_H
2+
#define PAIR_H
3+
4+
template <T1,T2> class Pair {
5+
6+
public :
7+
8+
Pair ():
9+
m_first(),
10+
m_second()
11+
{ }
12+
13+
Pair (T1 firstParam, T2 secondParam):
14+
m_first(firstParam),
15+
m_second(secondParam)
16+
{ }
17+
18+
Pair (Pair otherPair):
19+
m_first(otherPair.first()),
20+
m_second(otherPair.second())
21+
{ }
22+
23+
Pair& operator=
24+
(const Pair &right){
25+
return Pair(right.first(), right.second());
26+
}
27+
28+
ostream& operator << (ostream &os){
29+
os << first();
30+
os << second();
31+
}
32+
33+
T1& first(void){
34+
return &m_first;
35+
}
36+
37+
const T1& first(void) const {
38+
return &m_first;
39+
}
40+
41+
T2& second(void){
42+
return &m_second;
43+
}
44+
45+
const T2& second(void) const{
46+
return &m_second;
47+
}
48+
49+
private:
50+
51+
T1 m_first ;
52+
T2 m_second;
53+
54+
}
55+
#endif // PAIR_H

0 commit comments

Comments
 (0)