Build system improvements
[ustl.git] / upair.h
blobb4cc3b7b04e4ef8bf4a329c093ea4c4139f9a70f
1 // This file is part of the ustl library, an STL implementation.
2 //
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 /// \file upair.h
7 /// \brief Pair-related functionality.
9 #ifndef UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75
10 #define UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75
12 #include "utypes.h"
14 namespace ustl {
16 /// \class pair upair.h ustl.h
17 /// \ingroup AssociativeContainers
18 ///
19 /// \brief Container for two values.
20 ///
21 template <typename T1, typename T2>
22 class pair {
23 public:
24 typedef T1 first_type;
25 typedef T2 second_type;
26 public:
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); }
34 public:
35 first_type first;
36 second_type second;
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));
60 } // namespace ustl
62 #endif