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:
Mark Olesen 2021-05-04 14:25:28 +02:00
parent c0138ee8b6
commit 40567b844a
6 changed files with 16 additions and 33 deletions

View File

@ -55,6 +55,9 @@ See also
#include <numeric>
#include <functional>
// see issue #2083
#undef Foam_constructList_from_iterators
namespace Foam
{
@ -254,8 +257,12 @@ int main(int argc, char *argv[])
Info<< "list4: " << list4 << nl
<< "list5: " << list5 << endl;
#ifdef Foam_constructList_from_iterators
List<vector> list6(list4.begin(), list4.end());
Info<< "list6: " << list6 << endl;
#else
Info<< "NOTE: no construction from two iterators" << endl;
#endif
// Subset
const labelList map{0, 2};
@ -273,9 +280,13 @@ int main(int argc, char *argv[])
// scalarList slist = identity(15);
//
// More writing, but does work:
#ifdef Foam_constructList_from_iterators
scalarList slist(labelRange().begin(), labelRange(15).end());
Info<<"scalar identity:" << flatOutput(slist) << endl;
#else
Info<<"No iterator means of creating a scalar identity list" << endl;
#endif
printListOutputType<label>("labels") << nl;
@ -384,6 +395,7 @@ int main(int argc, char *argv[])
}
Info<< "sub-sorted: " << flatOutput(longLabelList) << nl;
#ifdef Foam_constructList_from_iterators
// Construct from a label-range
labelRange range(25,15);
@ -406,6 +418,10 @@ int main(int argc, char *argv[])
// Even weird things like this
List<scalar> sident4(labelRange().begin(), labelRange(8).end());
Info<<"range-list (scalar)=" << sident4 << nl;
#else
Info<< "NOTE: no construction of labelList from range pair" << nl
<< "use identity(...) instead" << endl;
#endif
}
wordReList reLst;

View File

@ -38,8 +38,6 @@ Description
#include "centredCPCCellToCellStencilObject.H"
#include "zoneDistribute.H"
#include "SortableList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])

View File

@ -122,11 +122,6 @@ public:
template<unsigned N>
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.
inline explicit DynamicList(std::initializer_list<T> lst);

View File

@ -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>
inline Foam::DynamicList<T, SizeMin>::DynamicList
(

View File

@ -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<unsigned N>
Foam::List<T>::List(const FixedList<T, N>& list)

View File

@ -160,11 +160,6 @@ public:
template<unsigned N>
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\>
template<unsigned N>
explicit List(const FixedList<T, N>& list);