mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: relocate hashing and IO for std::pair to Pair.H (from Tuple2.H)
- makes it more universally available
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -44,7 +44,8 @@ See also
|
|||||||
|
|
||||||
#include "FixedList.H"
|
#include "FixedList.H"
|
||||||
#include "Istream.H"
|
#include "Istream.H"
|
||||||
#include <utility> // For std::move
|
#include "Ostream.H"
|
||||||
|
#include <utility> // For std::move, std::pair
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -194,6 +195,16 @@ struct is_contiguous_scalar<Pair<T>> : is_contiguous_scalar<T> {};
|
|||||||
template<class T>
|
template<class T>
|
||||||
struct Hash<Pair<T>> : Pair<T>::hasher {};
|
struct Hash<Pair<T>> : Pair<T>::hasher {};
|
||||||
|
|
||||||
|
//- Hashing for std::pair data
|
||||||
|
template<class T1, class T2>
|
||||||
|
struct Hash<std::pair<T1, T2>>
|
||||||
|
{
|
||||||
|
unsigned operator()(const std::pair<T1, T2>& obj, unsigned seed=0) const
|
||||||
|
{
|
||||||
|
return Hash<T2>()(obj.second, Hash<T1>()(obj.first, seed));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -253,6 +264,32 @@ bool operator>=(const Pair<T>& a, const Pair<T>& b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//- Read std::pair from Istream
|
||||||
|
template<class T1, class T2>
|
||||||
|
inline Istream& operator>>(Istream& is, std::pair<T1,T2>& t)
|
||||||
|
{
|
||||||
|
is.readBegin("pair");
|
||||||
|
is >> t.first >> t.second;
|
||||||
|
is.readEnd("pair");
|
||||||
|
|
||||||
|
is.check(FUNCTION_NAME);
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Write std::pair to Ostream
|
||||||
|
template<class T1, class T2>
|
||||||
|
inline Ostream& operator<<(Ostream& os, const std::pair<T1,T2>& t)
|
||||||
|
{
|
||||||
|
os << token::BEGIN_LIST
|
||||||
|
<< t.first << token::SPACE << t.second
|
||||||
|
<< token::END_LIST;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -133,17 +133,6 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
//- Hashing for std::pair data
|
|
||||||
template<class T1, class T2>
|
|
||||||
struct Hash<std::pair<T1, T2>>
|
|
||||||
{
|
|
||||||
unsigned operator()(const std::pair<T1, T2>& obj, unsigned seed=0) const
|
|
||||||
{
|
|
||||||
return Hash<T2>()(obj.second, Hash<T1>()(obj.first, seed));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//- Hashing for Tuple2 data
|
//- Hashing for Tuple2 data
|
||||||
template<class T1, class T2>
|
template<class T1, class T2>
|
||||||
struct Hash<Tuple2<T1, T2>>
|
struct Hash<Tuple2<T1, T2>>
|
||||||
@ -291,19 +280,6 @@ struct maxFirstEqOp
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
//- Read std::pair from Istream
|
|
||||||
template<class T1, class T2>
|
|
||||||
inline Istream& operator>>(Istream& is, std::pair<T1,T2>& t)
|
|
||||||
{
|
|
||||||
is.readBegin("pair");
|
|
||||||
is >> t.first >> t.second;
|
|
||||||
is.readEnd("pair");
|
|
||||||
|
|
||||||
is.check(FUNCTION_NAME);
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Read Tuple2 from Istream
|
//- Read Tuple2 from Istream
|
||||||
template<class T1, class T2>
|
template<class T1, class T2>
|
||||||
inline Istream& operator>>(Istream& is, Tuple2<T1,T2>& t)
|
inline Istream& operator>>(Istream& is, Tuple2<T1,T2>& t)
|
||||||
@ -317,18 +293,7 @@ inline Istream& operator>>(Istream& is, Tuple2<T1,T2>& t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Write std::pair to Ostream.
|
//- Write Tuple2 to Ostream
|
||||||
template<class T1, class T2>
|
|
||||||
inline Ostream& operator<<(Ostream& os, const std::pair<T1,T2>& t)
|
|
||||||
{
|
|
||||||
os << token::BEGIN_LIST
|
|
||||||
<< t.first << token::SPACE << t.second
|
|
||||||
<< token::END_LIST;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//- Write Tuple2 to Ostream.
|
|
||||||
template<class T1, class T2>
|
template<class T1, class T2>
|
||||||
inline Ostream& operator<<(Ostream& os, const Tuple2<T1,T2>& t)
|
inline Ostream& operator<<(Ostream& os, const Tuple2<T1,T2>& t)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user