//! \addtogroup Containers //! \{ //! \file pipair.h //! \brief //! \~english Declares \a PIPair //! \~russian Объявление \a PIPair //! \~\authors //! \~english //! Ivan Pelipenko peri4ko@yandex.ru; //! Andrey Bychkov work.a.b@yandex.ru; //! \~russian //! Иван Пелипенко peri4ko@yandex.ru; //! Андрей Бычков work.a.b@yandex.ru; //! \~\} /* PIP - Platform Independent Primitives pair Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef PIPAIR_H #define PIPAIR_H #include "picout.h" //! \addtogroup Containers //! \{ //! \class PIPair //! \brief //! \~english //! \~russian Класс, который позволяет хранить два разнородных объекта как единое целое. //! \~\} //! \details //! \~english //! \~russian //! \~\sa \a PIMap template class PIPair { public: PIPair() : first(), second() {} PIPair(std::tuple tuple) { first = std::get<0>(tuple); second = std::get<1>(tuple); } PIPair(const Type0 & value0, const Type1 & value1) { first = value0; second = value1; } PIPair(Type0 && value0, Type1 && value1) { first = std::move(value0); second = std::move(value1); } Type0 first; Type1 second; }; //! \~english Compare operator with PIPair. //! \~russian Оператор сравнения с PIPair. template inline bool operator ==(const PIPair & value0, const PIPair & value1) { return (value0.first == value1.first) && (value0.second == value1.second); } //! \~english Compare operator with PIPair. //! \~russian Оператор сравнения с PIPair. template inline bool operator !=(const PIPair & value0, const PIPair & value1) { return (value0.first != value1.first) || (value0.second != value1.second); } #ifdef PIP_STD_IOSTREAM template inline std::ostream & operator <<(std::ostream & s, const PIPair & v) { s << "(" << v.first << ", " << v.second << ")"; return s; } #endif template inline PICout operator <<(PICout s, const PIPair & v) { s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s; } //! \~english Creates \a PIPair object, deducing the target type from the types of arguments. //! \~russian Создает \a PIPair выводя типы из аргументов. //! \~\details //! \~\code //! auto p = createPIPair(1, 'a'); //! piCout << p; // (1, a) //! \endcode template< class T1, class T2 > PIPair createPIPair(const T1 & f, const T2 & s) { return PIPair(f, s); } //! \~english Creates \a PIPair object, deducing the target type from the types of arguments. //! \~russian Создает \a PIPair выводя типы из аргументов. //! \sa \a createPIPair() template< class T1, class T2 > PIPair createPIPair(T1 && f, T2 && s) { return PIPair(std::move(f), std::move(s)); } #endif // PIPAIR_H