1 // This file is part of the ustl library, an STL implementation. 2 // 3 // Copyright (C) 2005 by Mike Sharov <msharov (at) users.sourceforge.net> 4 // This file is free software, distributed under the MIT License. 5 // 6 /// \file upair.h 7 /// \brief Pair-related functionality. 8 9 #ifndef UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75 10 #define UPAIR_H_7DC08F1B7FECF8AE6856D84C3B617A75 11 12 #include "utypes.h" 13 14 namespace ustl { 15 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; 37 }; 38 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) 42 { 43 return (p1.first == p2.first && p1.second == p2.second); 44 } 45 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) 49 { 50 return (p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second)); 51 } 52 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) 56 { 57 return (pair<T1,T2> (a, b)); 58 } 59 60 } // namespace ustl 61 62 #endif 63 64