alpar@906: /* -*- C++ -*- ladanyi@1435: * lemon/bits/extended_pair.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@1164: * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1359: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@921: #ifndef LEMON_EXTENDED_PAIR_H alpar@921: #define LEMON_EXTENDED_PAIR_H deba@782: deba@1430: ///\ingroup misc deba@1430: ///\file deba@1430: ///\brief A more customizable pair type than std::pair. deba@782: deba@1430: namespace lemon { deba@1430: deba@1430: /// \brief A more customizable pair type than std::pair. deba@1430: /// deba@1430: /// This type is a customizable pair type. The main goal deba@1430: /// is that the constructor's parameter type does not depend deba@1430: /// on the stored data type. This way it is possible to store deba@1430: /// references in the extended_pair. deba@1430: /// \code deba@1430: /// int a; char b; deba@1430: /// typedef extended_pair ICPair; deba@1430: /// ICPair p(a, b); deba@1430: /// // like a real reference to an std::pair deba@1430: /// // but the pair does not exist deba@1430: /// p.first = 42; deba@1430: /// p.second = '@'; deba@1430: /// \endcode deba@1430: /// \param T1 The type of first. deba@1430: /// \param A1 The parameter type for first. deba@1430: /// \param T2 The type of second. deba@1430: /// \param A2 The parameter type for second. deba@1430: template deba@1430: struct extended_pair { deba@1430: /// \brief The type of first. deba@1430: /// deba@1430: /// The type of first. deba@1430: typedef T1 first_type; deba@1430: /// \brief The type of second. deba@1430: /// deba@1430: /// The type of second. deba@1430: typedef T2 second_type; deba@782: deba@1430: /// \brief Default constructor. deba@1430: /// deba@1430: /// Default constructor. It calls the default constructor of deba@1430: /// first and second. deba@1430: extended_pair() : first(), second() {} deba@782: deba@1430: /// \brief Constructor. deba@1430: /// deba@1430: /// Constructor. deba@1430: extended_pair(A1 f, A2 s) : first(f), second(s) {} deba@782: deba@1430: /// \brief Template constructor. deba@1430: /// deba@1430: /// Template constructor. It copies everything which has deba@1430: /// \c first and \c second member. deba@1430: template deba@1430: extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {} deba@782: deba@1430: /// \brief The first value deba@1430: /// deba@1430: /// The first value deba@1430: T1 first; deba@1430: /// \brief The second value deba@1430: /// deba@1430: /// The second value deba@1430: T2 second; deba@1430: }; deba@1430: deba@1430: /// \brief Equality operator deba@1430: /// deba@1430: /// Equality operator deba@1430: template deba@1430: bool operator==(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return left.first == right.first && left.second == right.second; deba@1430: } deba@1430: deba@1430: /// \brief Inequality operator. deba@1430: /// deba@1430: /// Inequality operator. deba@1430: template deba@1430: bool operator!=(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return !(left == right); deba@1430: } deba@1430: deba@1430: /// \brief Less operator. deba@1430: /// deba@1430: /// Less operator. deba@1430: template deba@1430: bool operator<(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return left.first < right.first || deba@1430: (!(right.first deba@1430: bool operator>(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return right < left; deba@1430: } deba@1430: deba@1430: /// \brief Less or equal operator. deba@1430: /// deba@1430: /// Less or equal operator. deba@1430: template deba@1430: bool operator<=(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return !(right > left); deba@1430: } deba@1430: deba@1430: /// \brief Greater or equal operator. deba@1430: /// deba@1430: /// Greater or equal operator. deba@1430: template deba@1430: bool operator>=(const extended_pair& left, deba@1430: const extended_pair& right) { deba@1430: return !(right < left); deba@1430: } deba@1430: deba@782: } deba@782: #endif