PIPair refactoring
This commit is contained in:
@@ -165,8 +165,8 @@ template <typename C> _PIReverseWrapper<C> PIReverseWrap(const C & c) {return _P
|
|||||||
//! \~russian Порядок обхода для функции изменения размерности reshape().
|
//! \~russian Порядок обхода для функции изменения размерности reshape().
|
||||||
//! \~ \sa \a PIVector::reshape(), \a PIDeque::reshape()
|
//! \~ \sa \a PIVector::reshape(), \a PIDeque::reshape()
|
||||||
enum ReshapeOrder {
|
enum ReshapeOrder {
|
||||||
ReshapeByRow,
|
ReshapeByRow /*! \~english Traversing elements by line, just as they stay in memory \~russian Обход элементов построчно, так же как они находятся в памяти */,
|
||||||
ReshapeByColumn
|
ReshapeByColumn /*! \~english Traversing elements by column \~russian Обход элементов по столбцам */,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PICONTAINERS_H
|
#endif // PICONTAINERS_H
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
/*! \file pipair.h
|
//! \addtogroup Containers
|
||||||
* \brief pair
|
//! \{
|
||||||
*
|
//! \file pipair.h
|
||||||
* This file declare PIPair
|
//! \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
|
PIP - Platform Independent Primitives
|
||||||
pair
|
pair
|
||||||
@@ -27,30 +36,88 @@
|
|||||||
|
|
||||||
#include "picout.h"
|
#include "picout.h"
|
||||||
|
|
||||||
class PICout;
|
|
||||||
|
|
||||||
|
//! \addtogroup Containers
|
||||||
|
//! \{
|
||||||
|
//! \class PIPair
|
||||||
|
//! \brief
|
||||||
|
//! \~english
|
||||||
|
//! \~russian Класс, который позволяет хранить два разнородных объекта как единое целое.
|
||||||
|
//! \~\}
|
||||||
|
//! \details
|
||||||
|
//! \~english
|
||||||
|
//! \~russian
|
||||||
|
//! \~\sa \a PIMap
|
||||||
template<typename Type0, typename Type1>
|
template<typename Type0, typename Type1>
|
||||||
class PIPair {
|
class PIPair {
|
||||||
public:
|
public:
|
||||||
PIPair() {first = Type0(); second = Type1();}
|
PIPair() : first(), second() {}
|
||||||
PIPair(std::tuple<Type0, Type1> tuple) {first = std::get<0>(tuple); second = std::get<1>(tuple);}
|
PIPair(std::tuple<Type0, Type1> tuple) {
|
||||||
PIPair(const Type0 & value0, const Type1 & value1) {first = value0; second = value1;}
|
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;
|
Type0 first;
|
||||||
Type1 second;
|
Type1 second;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \~english Compare operator with PIPair.
|
||||||
|
//! \~russian Оператор сравнения с PIPair.
|
||||||
template<typename Type0, typename Type1>
|
template<typename Type0, typename Type1>
|
||||||
inline bool operator <(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {return value0.first < value1.first;}
|
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>
|
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);}
|
inline bool operator !=(const PIPair<Type0, Type1> & value0, const PIPair<Type0, Type1> & value1) {
|
||||||
template<typename Type0, typename Type1>
|
return (value0.first != value1.first) || (value0.second != value1.second);
|
||||||
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
|
#ifdef PIP_STD_IOSTREAM
|
||||||
template<typename Type0, typename Type1>
|
template<typename Type0, typename Type1>
|
||||||
inline std::ostream & operator <<(std::ostream & s, const PIPair<Type0, Type1> & v) {s << "(" << v.first << ", " << v.second << ")"; return s;}
|
inline std::ostream & operator <<(std::ostream & s, const PIPair<Type0, Type1> & v) {
|
||||||
|
s << "(" << v.first << ", " << v.second << ")";
|
||||||
|
return s;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename Type0, typename Type1>
|
template<typename Type0, typename Type1>
|
||||||
inline PICout operator <<(PICout s, const PIPair<Type0, Type1> & v) {s.space(); s.setControl(0, true); s << "(" << v.first << ", " << v.second << ")"; s.restoreControl(); return s;}
|
inline PICout operator <<(PICout s, const PIPair<Type0, Type1> & 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<T1,T2> createPIPair(const T1 & f, const T2 & s) {
|
||||||
|
return PIPair<T1,T2>(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<T1,T2> createPIPair(T1 && f, T2 && s) {
|
||||||
|
return PIPair<T1,T2>(std::move(f), std::move(s));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // PIPAIR_H
|
#endif // PIPAIR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user