COIN-OR::LEMON - Graph Library

Changeset 1430:48b4f46f9d4e in lemon-0.x


Ignore:
Timestamp:
05/19/05 13:53:25 (15 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1904
Message:

Documentation

May it should be renamed to ExtendedPair?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/bits/extended_pair.h

    r1359 r1430  
    11/* -*- C++ -*-
    2  * src/lemon/extended_pair.h - Part of LEMON, a generic C++ optimization library
     2 * src/lemon/bits/extended_pair.h - Part of LEMON, a generic C++ optimization library
    33 *
    44 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     
    1818#define LEMON_EXTENDED_PAIR_H
    1919
    20 template <typename T1, typename A1, typename T2, typename A2>
    21 struct extended_pair {
    22   typedef T1 first_type;
    23   typedef T2 second_type;
     20///\ingroup misc
     21///\file
     22///\brief A more customizable pair type than std::pair.
    2423
    25   extended_pair() : first(), second() {}
     24namespace lemon {
     25 
     26  /// \brief A more customizable pair type than std::pair.
     27  ///
     28  /// This type is a customizable pair type. The main goal
     29  /// is that the constructor's parameter type does not depend
     30  /// on the stored data type. This way it is possible to store
     31  /// references in the extended_pair.
     32  /// \code
     33  /// int a; char b;
     34  /// typedef extended_pair<int&, int&, char&, char&> ICPair;
     35  /// ICPair p(a, b);
     36  /// // like a real reference to an std::pair<int, char>
     37  /// // but the pair does not exist
     38  /// p.first = 42;
     39  /// p.second = '@';
     40  /// \endcode
     41  /// \param T1 The type of first.
     42  /// \param A1 The parameter type for first.
     43  /// \param T2 The type of second.
     44  /// \param A2 The parameter type for second.
     45  template <typename T1, typename A1, typename T2, typename A2>
     46  struct extended_pair {
     47    /// \brief The type of first.
     48    ///
     49    /// The type of first.
     50    typedef T1 first_type;
     51    /// \brief The type of second.
     52    ///
     53    /// The type of second.
     54    typedef T2 second_type;
    2655
    27   extended_pair(A1 f, A2 s) : first(f), second(s) {}
     56    /// \brief Default constructor.
     57    ///
     58    /// Default constructor. It calls the default constructor of
     59    /// first and second.
     60    extended_pair() : first(), second() {}
    2861
    29   template <class Pair>
    30   extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
     62    /// \brief Constructor.
     63    ///
     64    /// Constructor.
     65    extended_pair(A1 f, A2 s) : first(f), second(s) {}
    3166
    32   T1 first;
    33   T2 second;
    34 };
     67    /// \brief Template constructor.
     68    ///
     69    /// Template constructor. It copies everything which has
     70    /// \c first and \c second member.
     71    template <class Pair>
     72    extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
    3573
    36 template <typename T1, typename T2,
    37           typename LA1, typename LA2, typename RA1, typename RA2>
    38 bool operator==(const extended_pair<T1, LA1, T2, LA2>& left,
    39                 const extended_pair<T1, RA1, T2, RA2>& right) {
    40   return left.first == right.first && left.second == right.second;
     74    /// \brief The first value
     75    ///
     76    /// The first value
     77    T1 first;
     78    /// \brief The second value
     79    ///
     80    /// The second value
     81    T2 second;
     82  };
     83
     84  /// \brief Equality operator
     85  ///
     86  /// Equality operator
     87  template <typename T1, typename T2,
     88            typename LA1, typename LA2, typename RA1, typename RA2>
     89  bool operator==(const extended_pair<T1, LA1, T2, LA2>& left,
     90                  const extended_pair<T1, RA1, T2, RA2>& right) {
     91    return left.first == right.first && left.second == right.second;
     92  }
     93
     94  /// \brief Inequality operator.
     95  ///
     96  /// Inequality operator.
     97  template <typename T1, typename T2,
     98            typename LA1, typename LA2, typename RA1, typename RA2>
     99  bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left,
     100                  const extended_pair<T1, RA1, T2, RA2>& right) {
     101    return  !(left == right);
     102  }
     103
     104  /// \brief Less operator.
     105  ///
     106  /// Less operator.
     107  template <typename T1, typename T2,
     108            typename LA1, typename LA2, typename RA1, typename RA2>
     109  bool operator<(const extended_pair<T1, LA1, T2, LA2>& left,
     110                 const extended_pair<T1, RA1, T2, RA2>& right) {
     111    return left.first < right.first ||
     112      (!(right.first<left.first) && left.second < right.second);
     113  }
     114
     115  /// \brief Greater operator.
     116  ///
     117  /// Greater operator.
     118  template <typename T1, typename T2,
     119            typename LA1, typename LA2, typename RA1, typename RA2>
     120  bool operator>(const extended_pair<T1, LA1, T2, LA2>& left,
     121                 const extended_pair<T1, RA1, T2, RA2>& right) {
     122    return right < left;
     123  }
     124
     125  /// \brief Less or equal operator.
     126  ///
     127  /// Less or equal operator.
     128  template <typename T1, typename T2,
     129            typename LA1, typename LA2, typename RA1, typename RA2>
     130  bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left,
     131                  const extended_pair<T1, RA1, T2, RA2>& right) {
     132    return !(right > left);
     133  }
     134
     135  /// \brief Greater or equal operator.
     136  ///
     137  /// Greater or equal operator.
     138  template <typename T1, typename T2,
     139            typename LA1, typename LA2, typename RA1, typename RA2>
     140  bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left,
     141                  const extended_pair<T1, RA1, T2, RA2>& right) {
     142    return !(right < left);
     143  }
     144
    41145}
    42 
    43 template <typename T1, typename T2,
    44           typename LA1, typename LA2, typename RA1, typename RA2>
    45 bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left,
    46                 const extended_pair<T1, RA1, T2, RA2>& right) {
    47   return  !(left == right);
    48 }
    49 
    50 template <typename T1, typename T2,
    51           typename LA1, typename LA2, typename RA1, typename RA2>
    52 bool operator<(const extended_pair<T1, LA1, T2, LA2>& left,
    53                 const extended_pair<T1, RA1, T2, RA2>& right) {
    54   return left.first < right.first ||
    55            (!(right.first<left.first) && left.second < right.second);
    56 }
    57 
    58 template <typename T1, typename T2,
    59           typename LA1, typename LA2, typename RA1, typename RA2>
    60 bool operator>(const extended_pair<T1, LA1, T2, LA2>& left,
    61                 const extended_pair<T1, RA1, T2, RA2>& right) {
    62   return right < left;
    63 }
    64 
    65 template <typename T1, typename T2,
    66           typename LA1, typename LA2, typename RA1, typename RA2>
    67 bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left,
    68                 const extended_pair<T1, RA1, T2, RA2>& right) {
    69   return !(right > left);
    70 }
    71 
    72 template <typename T1, typename T2,
    73           typename LA1, typename LA2, typename RA1, typename RA2>
    74 bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left,
    75                 const extended_pair<T1, RA1, T2, RA2>& right) {
    76   return !(right < left);
    77 }
    78 
    79 
    80146#endif
Note: See TracChangeset for help on using the changeset viewer.