# HG changeset patch # User deba # Date 1116503605 0 # Node ID 48b4f46f9d4e18b12ed8511be90e5ba68b5dedaa # Parent 4283998fb2be8e4f4ff82c53dce18a1b8e7e6d5d Documentation May it should be renamed to ExtendedPair diff -r 4283998fb2be -r 48b4f46f9d4e src/lemon/bits/extended_pair.h --- a/src/lemon/bits/extended_pair.h Thu May 19 11:49:42 2005 +0000 +++ b/src/lemon/bits/extended_pair.h Thu May 19 11:53:25 2005 +0000 @@ -1,5 +1,5 @@ /* -*- C++ -*- - * src/lemon/extended_pair.h - Part of LEMON, a generic C++ optimization library + * src/lemon/bits/extended_pair.h - Part of LEMON, a generic C++ optimization library * * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). @@ -17,64 +17,130 @@ #ifndef LEMON_EXTENDED_PAIR_H #define LEMON_EXTENDED_PAIR_H -template -struct extended_pair { - typedef T1 first_type; - typedef T2 second_type; +///\ingroup misc +///\file +///\brief A more customizable pair type than std::pair. - extended_pair() : first(), second() {} +namespace lemon { + + /// \brief A more customizable pair type than std::pair. + /// + /// This type is a customizable pair type. The main goal + /// is that the constructor's parameter type does not depend + /// on the stored data type. This way it is possible to store + /// references in the extended_pair. + /// \code + /// int a; char b; + /// typedef extended_pair ICPair; + /// ICPair p(a, b); + /// // like a real reference to an std::pair + /// // but the pair does not exist + /// p.first = 42; + /// p.second = '@'; + /// \endcode + /// \param T1 The type of first. + /// \param A1 The parameter type for first. + /// \param T2 The type of second. + /// \param A2 The parameter type for second. + template + struct extended_pair { + /// \brief The type of first. + /// + /// The type of first. + typedef T1 first_type; + /// \brief The type of second. + /// + /// The type of second. + typedef T2 second_type; - extended_pair(A1 f, A2 s) : first(f), second(s) {} + /// \brief Default constructor. + /// + /// Default constructor. It calls the default constructor of + /// first and second. + extended_pair() : first(), second() {} - template - extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {} + /// \brief Constructor. + /// + /// Constructor. + extended_pair(A1 f, A2 s) : first(f), second(s) {} - T1 first; - T2 second; -}; + /// \brief Template constructor. + /// + /// Template constructor. It copies everything which has + /// \c first and \c second member. + template + extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {} -template -bool operator==(const extended_pair& left, - const extended_pair& right) { - return left.first == right.first && left.second == right.second; + /// \brief The first value + /// + /// The first value + T1 first; + /// \brief The second value + /// + /// The second value + T2 second; + }; + + /// \brief Equality operator + /// + /// Equality operator + template + bool operator==(const extended_pair& left, + const extended_pair& right) { + return left.first == right.first && left.second == right.second; + } + + /// \brief Inequality operator. + /// + /// Inequality operator. + template + bool operator!=(const extended_pair& left, + const extended_pair& right) { + return !(left == right); + } + + /// \brief Less operator. + /// + /// Less operator. + template + bool operator<(const extended_pair& left, + const extended_pair& right) { + return left.first < right.first || + (!(right.first + bool operator>(const extended_pair& left, + const extended_pair& right) { + return right < left; + } + + /// \brief Less or equal operator. + /// + /// Less or equal operator. + template + bool operator<=(const extended_pair& left, + const extended_pair& right) { + return !(right > left); + } + + /// \brief Greater or equal operator. + /// + /// Greater or equal operator. + template + bool operator>=(const extended_pair& left, + const extended_pair& right) { + return !(right < left); + } + } - -template -bool operator!=(const extended_pair& left, - const extended_pair& right) { - return !(left == right); -} - -template -bool operator<(const extended_pair& left, - const extended_pair& right) { - return left.first < right.first || - (!(right.first -bool operator>(const extended_pair& left, - const extended_pair& right) { - return right < left; -} - -template -bool operator<=(const extended_pair& left, - const extended_pair& right) { - return !(right > left); -} - -template -bool operator>=(const extended_pair& left, - const extended_pair& right) { - return !(right < left); -} - - #endif