1.1 --- a/lemon/bits/extended_pair.h Mon Nov 21 18:03:20 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,146 +0,0 @@
1.4 -/* -*- C++ -*-
1.5 - * lemon/bits/extended_pair.h - Part of LEMON, a generic C++ optimization library
1.6 - *
1.7 - * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.8 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.9 - *
1.10 - * Permission to use, modify and distribute this software is granted
1.11 - * provided that this copyright notice appears in all copies. For
1.12 - * precise terms see the accompanying LICENSE file.
1.13 - *
1.14 - * This software is provided "AS IS" with no warranty of any kind,
1.15 - * express or implied, and with no claim as to its suitability for any
1.16 - * purpose.
1.17 - *
1.18 - */
1.19 -
1.20 -#ifndef LEMON_EXTENDED_PAIR_H
1.21 -#define LEMON_EXTENDED_PAIR_H
1.22 -
1.23 -///\ingroup misc
1.24 -///\file
1.25 -///\brief A more customizable pair type than std::pair.
1.26 -
1.27 -namespace lemon {
1.28 -
1.29 - /// \brief A more customizable pair type than std::pair.
1.30 - ///
1.31 - /// This type is a customizable pair type. The main goal
1.32 - /// is that the constructor's parameter type does not depend
1.33 - /// on the stored data type. This way it is possible to store
1.34 - /// references in the extended_pair.
1.35 - /// \code
1.36 - /// int a; char b;
1.37 - /// typedef extended_pair<int&, int&, char&, char&> ICPair;
1.38 - /// ICPair p(a, b);
1.39 - /// // like a real reference to an std::pair<int, char>
1.40 - /// // but the pair does not exist
1.41 - /// p.first = 42;
1.42 - /// p.second = '@';
1.43 - /// \endcode
1.44 - /// \param T1 The type of first.
1.45 - /// \param A1 The parameter type for first.
1.46 - /// \param T2 The type of second.
1.47 - /// \param A2 The parameter type for second.
1.48 - template <typename T1, typename A1, typename T2, typename A2>
1.49 - struct extended_pair {
1.50 - /// \brief The type of first.
1.51 - ///
1.52 - /// The type of first.
1.53 - typedef T1 first_type;
1.54 - /// \brief The type of second.
1.55 - ///
1.56 - /// The type of second.
1.57 - typedef T2 second_type;
1.58 -
1.59 - /// \brief Default constructor.
1.60 - ///
1.61 - /// Default constructor. It calls the default constructor of
1.62 - /// first and second.
1.63 - extended_pair() : first(), second() {}
1.64 -
1.65 - /// \brief Constructor.
1.66 - ///
1.67 - /// Constructor.
1.68 - extended_pair(A1 f, A2 s) : first(f), second(s) {}
1.69 -
1.70 - /// \brief Template constructor.
1.71 - ///
1.72 - /// Template constructor. It copies everything which has
1.73 - /// \c first and \c second member.
1.74 - template <class Pair>
1.75 - extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
1.76 -
1.77 - /// \brief The first value
1.78 - ///
1.79 - /// The first value
1.80 - T1 first;
1.81 - /// \brief The second value
1.82 - ///
1.83 - /// The second value
1.84 - T2 second;
1.85 - };
1.86 -
1.87 - /// \brief Equality operator
1.88 - ///
1.89 - /// Equality operator
1.90 - template <typename T1, typename T2,
1.91 - typename LA1, typename LA2, typename RA1, typename RA2>
1.92 - bool operator==(const extended_pair<T1, LA1, T2, LA2>& left,
1.93 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.94 - return left.first == right.first && left.second == right.second;
1.95 - }
1.96 -
1.97 - /// \brief Inequality operator.
1.98 - ///
1.99 - /// Inequality operator.
1.100 - template <typename T1, typename T2,
1.101 - typename LA1, typename LA2, typename RA1, typename RA2>
1.102 - bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left,
1.103 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.104 - return !(left == right);
1.105 - }
1.106 -
1.107 - /// \brief Less operator.
1.108 - ///
1.109 - /// Less operator.
1.110 - template <typename T1, typename T2,
1.111 - typename LA1, typename LA2, typename RA1, typename RA2>
1.112 - bool operator<(const extended_pair<T1, LA1, T2, LA2>& left,
1.113 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.114 - return left.first < right.first ||
1.115 - (!(right.first<left.first) && left.second < right.second);
1.116 - }
1.117 -
1.118 - /// \brief Greater operator.
1.119 - ///
1.120 - /// Greater operator.
1.121 - template <typename T1, typename T2,
1.122 - typename LA1, typename LA2, typename RA1, typename RA2>
1.123 - bool operator>(const extended_pair<T1, LA1, T2, LA2>& left,
1.124 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.125 - return right < left;
1.126 - }
1.127 -
1.128 - /// \brief Less or equal operator.
1.129 - ///
1.130 - /// Less or equal operator.
1.131 - template <typename T1, typename T2,
1.132 - typename LA1, typename LA2, typename RA1, typename RA2>
1.133 - bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left,
1.134 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.135 - return !(right > left);
1.136 - }
1.137 -
1.138 - /// \brief Greater or equal operator.
1.139 - ///
1.140 - /// Greater or equal operator.
1.141 - template <typename T1, typename T2,
1.142 - typename LA1, typename LA2, typename RA1, typename RA2>
1.143 - bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left,
1.144 - const extended_pair<T1, RA1, T2, RA2>& right) {
1.145 - return !(right < left);
1.146 - }
1.147 -
1.148 -}
1.149 -#endif