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;