Documentation
authordeba
Thu, 19 May 2005 11:53:25 +0000
changeset 143048b4f46f9d4e
parent 1429 4283998fb2be
child 1431 ad44b1dd8013
Documentation

May it should be renamed to ExtendedPair
src/lemon/bits/extended_pair.h
     1.1 --- a/src/lemon/bits/extended_pair.h	Thu May 19 11:49:42 2005 +0000
     1.2 +++ b/src/lemon/bits/extended_pair.h	Thu May 19 11:53:25 2005 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /* -*- C++ -*-
     1.5 - * src/lemon/extended_pair.h - Part of LEMON, a generic C++ optimization library
     1.6 + * src/lemon/bits/extended_pair.h - Part of LEMON, a generic C++ optimization library
     1.7   *
     1.8   * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.9   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.10 @@ -17,64 +17,130 @@
    1.11  #ifndef LEMON_EXTENDED_PAIR_H
    1.12  #define LEMON_EXTENDED_PAIR_H
    1.13  
    1.14 -template <typename T1, typename A1, typename T2, typename A2>
    1.15 -struct extended_pair {
    1.16 -  typedef T1 first_type;
    1.17 -  typedef T2 second_type;
    1.18 +///\ingroup misc
    1.19 +///\file
    1.20 +///\brief A more customizable pair type than std::pair.
    1.21  
    1.22 -  extended_pair() : first(), second() {}
    1.23 +namespace lemon {
    1.24 +  
    1.25 +  /// \brief A more customizable pair type than std::pair.
    1.26 +  ///
    1.27 +  /// This type is a customizable pair type. The main goal
    1.28 +  /// is that the constructor's parameter type does not depend
    1.29 +  /// on the stored data type. This way it is possible to store
    1.30 +  /// references in the extended_pair.
    1.31 +  /// \code
    1.32 +  /// int a; char b;
    1.33 +  /// typedef extended_pair<int&, int&, char&, char&> ICPair;
    1.34 +  /// ICPair p(a, b); 
    1.35 +  /// // like a real reference to an std::pair<int, char>
    1.36 +  /// // but the pair does not exist
    1.37 +  /// p.first = 42;
    1.38 +  /// p.second = '@';
    1.39 +  /// \endcode
    1.40 +  /// \param T1 The type of first.
    1.41 +  /// \param A1 The parameter type for first.
    1.42 +  /// \param T2 The type of second.
    1.43 +  /// \param A2 The parameter type for second.
    1.44 +  template <typename T1, typename A1, typename T2, typename A2>
    1.45 +  struct extended_pair {
    1.46 +    /// \brief The type of first.
    1.47 +    ///
    1.48 +    /// The type of first.
    1.49 +    typedef T1 first_type;
    1.50 +    /// \brief The type of second.
    1.51 +    ///
    1.52 +    /// The type of second.
    1.53 +    typedef T2 second_type;
    1.54  
    1.55 -  extended_pair(A1 f, A2 s) : first(f), second(s) {}
    1.56 +    /// \brief Default constructor.
    1.57 +    ///
    1.58 +    /// Default constructor. It calls the default constructor of
    1.59 +    /// first and second.
    1.60 +    extended_pair() : first(), second() {}
    1.61  
    1.62 -  template <class Pair>
    1.63 -  extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
    1.64 +    /// \brief Constructor.
    1.65 +    ///
    1.66 +    /// Constructor. 
    1.67 +    extended_pair(A1 f, A2 s) : first(f), second(s) {}
    1.68  
    1.69 -  T1 first;
    1.70 -  T2 second;
    1.71 -};
    1.72 +    /// \brief Template constructor.
    1.73 +    ///
    1.74 +    /// Template constructor. It copies everything which has
    1.75 +    /// \c first and \c second member.
    1.76 +    template <class Pair>
    1.77 +    extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
    1.78  
    1.79 -template <typename T1, typename T2, 
    1.80 -	  typename LA1, typename LA2, typename RA1, typename RA2>
    1.81 -bool operator==(const extended_pair<T1, LA1, T2, LA2>& left, 
    1.82 -		const extended_pair<T1, RA1, T2, RA2>& right) {
    1.83 -  return left.first == right.first && left.second == right.second;
    1.84 +    /// \brief The first value
    1.85 +    /// 
    1.86 +    /// The first value
    1.87 +    T1 first;
    1.88 +    /// \brief The second value
    1.89 +    /// 
    1.90 +    /// The second value
    1.91 +    T2 second;
    1.92 +  };
    1.93 +
    1.94 +  /// \brief Equality operator
    1.95 +  /// 
    1.96 +  /// Equality operator
    1.97 +  template <typename T1, typename T2, 
    1.98 +	    typename LA1, typename LA2, typename RA1, typename RA2>
    1.99 +  bool operator==(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.100 +		  const extended_pair<T1, RA1, T2, RA2>& right) {
   1.101 +    return left.first == right.first && left.second == right.second;
   1.102 +  }
   1.103 +
   1.104 +  /// \brief Inequality operator.
   1.105 +  /// 
   1.106 +  /// Inequality operator.
   1.107 +  template <typename T1, typename T2, 
   1.108 +	    typename LA1, typename LA2, typename RA1, typename RA2>
   1.109 +  bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.110 +		  const extended_pair<T1, RA1, T2, RA2>& right) {
   1.111 +    return  !(left == right);
   1.112 +  }
   1.113 +
   1.114 +  /// \brief Less operator.
   1.115 +  /// 
   1.116 +  /// Less operator.
   1.117 +  template <typename T1, typename T2, 
   1.118 +	    typename LA1, typename LA2, typename RA1, typename RA2>
   1.119 +  bool operator<(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.120 +		 const extended_pair<T1, RA1, T2, RA2>& right) {
   1.121 +    return left.first < right.first || 
   1.122 +      (!(right.first<left.first) && left.second < right.second);
   1.123 +  }
   1.124 +
   1.125 +  /// \brief Greater operator.
   1.126 +  /// 
   1.127 +  /// Greater operator.
   1.128 +  template <typename T1, typename T2, 
   1.129 +	    typename LA1, typename LA2, typename RA1, typename RA2>
   1.130 +  bool operator>(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.131 +		 const extended_pair<T1, RA1, T2, RA2>& right) {
   1.132 +    return right < left;
   1.133 +  }
   1.134 +
   1.135 +  /// \brief Less or equal operator.
   1.136 +  /// 
   1.137 +  /// Less or equal operator.
   1.138 +  template <typename T1, typename T2, 
   1.139 +	    typename LA1, typename LA2, typename RA1, typename RA2>
   1.140 +  bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.141 +		  const extended_pair<T1, RA1, T2, RA2>& right) {
   1.142 +    return !(right > left);
   1.143 +  }
   1.144 +
   1.145 +  /// \brief Greater or equal operator.
   1.146 +  /// 
   1.147 +  /// Greater or equal operator.
   1.148 +  template <typename T1, typename T2, 
   1.149 +	    typename LA1, typename LA2, typename RA1, typename RA2>
   1.150 +  bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.151 +		  const extended_pair<T1, RA1, T2, RA2>& right) {
   1.152 +    return !(right < left);
   1.153 +  }
   1.154 +
   1.155  }
   1.156 -
   1.157 -template <typename T1, typename T2, 
   1.158 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   1.159 -bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.160 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   1.161 -  return  !(left == right);
   1.162 -}
   1.163 -
   1.164 -template <typename T1, typename T2, 
   1.165 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   1.166 -bool operator<(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.167 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   1.168 -  return left.first < right.first || 
   1.169 -           (!(right.first<left.first) && left.second < right.second);
   1.170 -}
   1.171 -
   1.172 -template <typename T1, typename T2, 
   1.173 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   1.174 -bool operator>(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.175 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   1.176 -  return right < left;
   1.177 -}
   1.178 -
   1.179 -template <typename T1, typename T2, 
   1.180 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   1.181 -bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.182 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   1.183 -  return !(right > left);
   1.184 -}
   1.185 -
   1.186 -template <typename T1, typename T2, 
   1.187 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   1.188 -bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left, 
   1.189 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   1.190 -  return !(right < left);
   1.191 -}
   1.192 -
   1.193 -
   1.194  #endif