mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: FixedList '<' operator using a template parameter (fixes #458)
- cannot use comparison of list sizes. Okay for UList, but not here. STYLE: - don't need two iterators for the '<' comparison, can just access internal storage directly
This commit is contained in:
@ -33,7 +33,6 @@ See also
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "IOstreams.H"
|
|
||||||
#include "FixedList.H"
|
#include "FixedList.H"
|
||||||
#include "IFstream.H"
|
#include "IFstream.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
@ -64,6 +63,15 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "list2:" << list2
|
Info<< "list2:" << list2
|
||||||
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
|
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
|
||||||
|
|
||||||
|
// Using FixedList for content too
|
||||||
|
{
|
||||||
|
List<FixedList<label, 4>> twolists{list, list2};
|
||||||
|
Info<<"List of FixedList: " << flatOutput(twolists) << endl;
|
||||||
|
sort(twolists);
|
||||||
|
// outer-sort only
|
||||||
|
Info<<"sorted FixedList : " << flatOutput(twolists) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
Info<< "list: " << list << nl
|
Info<< "list: " << list << nl
|
||||||
<< "list2: " << list2 << endl;
|
<< "list2: " << list2 << endl;
|
||||||
list.swap(list2);
|
list.swap(list2);
|
||||||
|
|||||||
@ -70,31 +70,24 @@ bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& a) const
|
|||||||
template<class T, unsigned Size>
|
template<class T, unsigned Size>
|
||||||
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const
|
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const
|
||||||
{
|
{
|
||||||
for
|
const T* const __restrict__ ptr1 = this->begin();
|
||||||
(
|
const T* const __restrict__ ptr2 = a.begin();
|
||||||
const_iterator vi = cbegin(), ai = a.cbegin();
|
|
||||||
vi < cend() && ai < a.cend();
|
for (unsigned i=0; i<Size; ++i)
|
||||||
vi++, ai++
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (*vi < *ai)
|
if (ptr1[i] < ptr2[i])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (*vi > *ai)
|
else if (ptr1[i] > ptr2[i])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Size < a.Size)
|
// Contents look to be identical.
|
||||||
{
|
// The sizes are identical by definition (template parameter)
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -196,14 +196,8 @@ bool Foam::UList<T>::operator<(const UList<T>& a) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->size_ < a.size_)
|
// Contents look to be identical, or lists have different sizes
|
||||||
{
|
return (this->size_ < a.size_);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user