137 lines
4.5 KiB
C++
137 lines
4.5 KiB
C++
//! \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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef PIPAIR_H
|
|
#define PIPAIR_H
|
|
|
|
#include "picout.h"
|
|
|
|
|
|
//! \addtogroup Containers
|
|
//! \{
|
|
//! \class PIPair
|
|
//! \brief
|
|
//! \~english Class template that provides a way to store two heterogeneous objects as a single unit.
|
|
//! \~russian Класс, который позволяет хранить два разнородных объекта как единое целое.
|
|
//! \~\}
|
|
//! \~\sa \a PIMap
|
|
template<typename Type0, typename Type1>
|
|
class PIPair {
|
|
public:
|
|
//! \~english Constructs an empty PIPair.
|
|
//! \~russian Создает пустой PIPair.
|
|
PIPair(): first(), second() {}
|
|
|
|
//! \~english Constructs PIPair from [std::tuple](https://en.cppreference.com/w/cpp/utility/tuple).
|
|
//! \~russian Создает PIPair из [std::tuple](https://ru.cppreference.com/w/cpp/utility/tuple).
|
|
explicit PIPair(std::tuple<Type0, Type1> tuple) {
|
|
first = std::get<0>(tuple);
|
|
second = std::get<1>(tuple);
|
|
}
|
|
|
|
//! \~english Constructs PIPair from [std::pair](https://en.cppreference.com/w/cpp/utility/pair).
|
|
//! \~russian Создает PIPair из [std::pair](https://ru.cppreference.com/w/cpp/utility/pair).
|
|
explicit PIPair(std::pair<Type0, Type1> pair) {
|
|
first = pair.first;
|
|
second = pair.second;
|
|
}
|
|
|
|
//! \~english Constructs PIPair from values `value0` and `value1`.
|
|
//! \~russian Создает PIPair из `value0` и `value1`.
|
|
PIPair(const Type0 & value0, const Type1 & value1) {
|
|
first = value0;
|
|
second = value1;
|
|
}
|
|
|
|
//! \~english Move constructor.
|
|
//! \~russian Перемещающий конструктор.
|
|
PIPair(Type0 && value0, Type1 && value1) {
|
|
first = std::move(value0);
|
|
second = std::move(value1);
|
|
}
|
|
|
|
//! \~english First element.
|
|
//! \~russian Первый элемент.
|
|
Type0 first;
|
|
|
|
//! \~english Second element.
|
|
//! \~russian Второй элемент.
|
|
Type1 second;
|
|
};
|
|
|
|
//! \~english Compare operator with PIPair.
|
|
//! \~russian Оператор сравнения с PIPair.
|
|
template<typename Type0, typename Type1>
|
|
inline bool operator==(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {
|
|
return (value0.first == value1.first) && (value0.second == value1.second);
|
|
}
|
|
|
|
//! \~english Compare operator with PIPair.
|
|
//! \~russian Оператор сравнения с PIPair.
|
|
template<typename Type0, typename Type1>
|
|
inline bool operator!=(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {
|
|
return (value0.first != value1.first) || (value0.second != value1.second);
|
|
}
|
|
|
|
#ifdef PIP_STD_IOSTREAM
|
|
template<typename Type0, typename Type1>
|
|
inline std::ostream & operator<<(std::ostream & s, const PIPair<Type0, Type1> & v) {
|
|
s << "(" << v.first << ", " << v.second << ")";
|
|
return s;
|
|
}
|
|
#endif
|
|
|
|
//! \relatesalso PICout
|
|
//! \~english Output operator to \a PICout
|
|
//! \~russian Оператор вывода в \a PICout
|
|
template<typename Type0, typename Type1>
|
|
inline PICout operator<<(PICout s, const PIPair<Type0, Type1> & v) {
|
|
s.space();
|
|
s.saveAndSetControls(0);
|
|
s << "(" << v.first << ", " << v.second << ")";
|
|
s.restoreControls();
|
|
return 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<T1, T2> createPIPair(T1 f, T2 s) {
|
|
return PIPair<T1, T2>(std::move(f), std::move(s));
|
|
}
|
|
|
|
|
|
#endif // PIPAIR_H
|