1 // This file is part of the ustl library, an STL implementation.
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
7 /// \brief Pair-related functionality.
9 #ifndef UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75
10 #define UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75
16 /// \class pair upair.h ustl.h
17 /// \ingroup AssociativeContainers
19 /// \brief Container for two values.
21 template <typename T1
, typename T2
>
24 typedef T1 first_type
;
25 typedef T2 second_type
;
27 /// Default constructor.
28 inline pair (void) : first (T1()), second (T2()) {}
29 /// Initializes members with \p a, and \p b.
30 inline pair (const T1
& a
, const T2
& b
) : first (a
), second (b
) {}
31 inline pair
& operator= (const pair
<T1
, T2
>& p2
) { first
= p2
.first
; second
= p2
.second
; return (*this); }
32 template <typename T3
, typename T4
>
33 inline pair
& operator= (const pair
<T3
, T4
>& p2
) { first
= p2
.first
; second
= p2
.second
; return (*this); }
39 /// Compares both values of \p p1 to those of \p p2.
40 template <typename T1
, typename T2
>
41 inline bool operator== (const pair
<T1
,T2
>& p1
, const pair
<T1
,T2
>& p2
)
43 return (p1
.first
== p2
.first
&& p1
.second
== p2
.second
);
46 /// Compares both values of \p p1 to those of \p p2.
47 template <typename T1
, typename T2
>
48 bool operator< (const pair
<T1
,T2
>& p1
, const pair
<T1
,T2
>& p2
)
50 return (p1
.first
< p2
.first
|| (p1
.first
== p2
.first
&& p1
.second
< p2
.second
));
53 /// Returns a pair object with (a,b)
54 template <typename T1
, typename T2
>
55 inline pair
<T1
,T2
> make_pair (const T1
& a
, const T2
& b
)
57 return (pair
<T1
,T2
> (a
, b
));