mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
DEFEATURE: remove construct List from two iterators (#2083)
- this constructor was added for similarity with std::vector,
but continues to cause various annoyances.
The main problem is that the templated parameter tends to grab
anything that is not a perfect match for other constructors.
Typically seen with two integers (in 64-bit mode), but various other
cases as well.
If required, the ListOps::create() function provides a lengthier
alternative but one that can also incorporate transformations.
Eg,
pointField pts = ....;
List<scalar> mags
(
List<scalar>::create
(
pts.begin(),
pts.end(),
[](const vector& v){ return magSqr(v); }
);
This commit is contained in:
@ -55,6 +55,9 @@ See also
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
// see issue #2083
|
||||||
|
#undef Foam_constructList_from_iterators
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -254,8 +257,12 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "list4: " << list4 << nl
|
Info<< "list4: " << list4 << nl
|
||||||
<< "list5: " << list5 << endl;
|
<< "list5: " << list5 << endl;
|
||||||
|
|
||||||
|
#ifdef Foam_constructList_from_iterators
|
||||||
List<vector> list6(list4.begin(), list4.end());
|
List<vector> list6(list4.begin(), list4.end());
|
||||||
Info<< "list6: " << list6 << endl;
|
Info<< "list6: " << list6 << endl;
|
||||||
|
#else
|
||||||
|
Info<< "NOTE: no construction from two iterators" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Subset
|
// Subset
|
||||||
const labelList map{0, 2};
|
const labelList map{0, 2};
|
||||||
@ -273,9 +280,13 @@ int main(int argc, char *argv[])
|
|||||||
// scalarList slist = identity(15);
|
// scalarList slist = identity(15);
|
||||||
//
|
//
|
||||||
// More writing, but does work:
|
// More writing, but does work:
|
||||||
|
#ifdef Foam_constructList_from_iterators
|
||||||
scalarList slist(labelRange().begin(), labelRange(15).end());
|
scalarList slist(labelRange().begin(), labelRange(15).end());
|
||||||
|
|
||||||
Info<<"scalar identity:" << flatOutput(slist) << endl;
|
Info<<"scalar identity:" << flatOutput(slist) << endl;
|
||||||
|
#else
|
||||||
|
Info<<"No iterator means of creating a scalar identity list" << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
printListOutputType<label>("labels") << nl;
|
printListOutputType<label>("labels") << nl;
|
||||||
|
|
||||||
@ -384,6 +395,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
|
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
|
||||||
|
|
||||||
|
#ifdef Foam_constructList_from_iterators
|
||||||
// Construct from a label-range
|
// Construct from a label-range
|
||||||
labelRange range(25,15);
|
labelRange range(25,15);
|
||||||
|
|
||||||
@ -406,6 +418,10 @@ int main(int argc, char *argv[])
|
|||||||
// Even weird things like this
|
// Even weird things like this
|
||||||
List<scalar> sident4(labelRange().begin(), labelRange(8).end());
|
List<scalar> sident4(labelRange().begin(), labelRange(8).end());
|
||||||
Info<<"range-list (scalar)=" << sident4 << nl;
|
Info<<"range-list (scalar)=" << sident4 << nl;
|
||||||
|
#else
|
||||||
|
Info<< "NOTE: no construction of labelList from range pair" << nl
|
||||||
|
<< "use identity(...) instead" << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wordReList reLst;
|
wordReList reLst;
|
||||||
|
|||||||
@ -38,8 +38,6 @@ Description
|
|||||||
#include "centredCPCCellToCellStencilObject.H"
|
#include "centredCPCCellToCellStencilObject.H"
|
||||||
#include "zoneDistribute.H"
|
#include "zoneDistribute.H"
|
||||||
|
|
||||||
#include "SortableList.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@ -122,11 +122,6 @@ public:
|
|||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
inline DynamicList(const FixedList<T, N>& lst);
|
inline DynamicList(const FixedList<T, N>& lst);
|
||||||
|
|
||||||
//- Construct given begin/end iterators.
|
|
||||||
// Uses std::distance to determine the size.
|
|
||||||
template<class InputIterator>
|
|
||||||
inline DynamicList(InputIterator begIter, InputIterator endIter);
|
|
||||||
|
|
||||||
//- Construct from an initializer list. Size set to list size.
|
//- Construct from an initializer list. Size set to list size.
|
||||||
inline explicit DynamicList(std::initializer_list<T> lst);
|
inline explicit DynamicList(std::initializer_list<T> lst);
|
||||||
|
|
||||||
|
|||||||
@ -147,19 +147,6 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, int SizeMin>
|
|
||||||
template<class InputIterator>
|
|
||||||
inline Foam::DynamicList<T, SizeMin>::DynamicList
|
|
||||||
(
|
|
||||||
InputIterator begIter,
|
|
||||||
InputIterator endIter
|
|
||||||
)
|
|
||||||
:
|
|
||||||
List<T>(begIter, endIter),
|
|
||||||
capacity_(List<T>::size())
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, int SizeMin>
|
template<class T, int SizeMin>
|
||||||
inline Foam::DynamicList<T, SizeMin>::DynamicList
|
inline Foam::DynamicList<T, SizeMin>::DynamicList
|
||||||
(
|
(
|
||||||
|
|||||||
@ -336,14 +336,6 @@ Foam::List<T>::List
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
template<class InputIterator>
|
|
||||||
Foam::List<T>::List(InputIterator begIter, InputIterator endIter)
|
|
||||||
:
|
|
||||||
List<T>(begIter, endIter, std::distance(begIter, endIter))
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
Foam::List<T>::List(const FixedList<T, N>& list)
|
Foam::List<T>::List(const FixedList<T, N>& list)
|
||||||
|
|||||||
@ -160,11 +160,6 @@ public:
|
|||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
List(const UList<T>& list, const FixedList<label, N>& indices);
|
List(const UList<T>& list, const FixedList<label, N>& indices);
|
||||||
|
|
||||||
//- Construct given begin/end iterators.
|
|
||||||
// Uses std::distance for the size.
|
|
||||||
template<class InputIterator>
|
|
||||||
List(InputIterator begIter, InputIterator endIter);
|
|
||||||
|
|
||||||
//- Construct as copy of FixedList\<T, N\>
|
//- Construct as copy of FixedList\<T, N\>
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
explicit List(const FixedList<T, N>& list);
|
explicit List(const FixedList<T, N>& list);
|
||||||
|
|||||||
Reference in New Issue
Block a user