ENH: copy construct FixedList from fixed subset of input

- remove construct from two iterators (#2083)
This commit is contained in:
Mark Olesen
2021-07-15 13:08:54 +02:00
parent 0c15f773e0
commit db9460f0bc
3 changed files with 38 additions and 31 deletions

View File

@ -280,16 +280,24 @@ int main(int argc, char *argv[])
List<label> list3{0, 1, 2, 3}; List<label> list3{0, 1, 2, 3};
FixedList<label, 4> list4(list3.begin(), list3.end()); FixedList<label, 4> list4(list3);
Info<< "list3: " << list3 << nl Info<< "list3: " << list3 << nl
<< "list4: " << list4 << nl; << "list4: " << list4 << nl;
list4 = {1, 2, 3, 5}; list4 = {1, 20, 3, 40};
Info<< "list4: " << list4 << nl; Info<< "list4: " << list4 << nl;
FixedList<label, 5> list5{0, 1, 2, 3, 4}; FixedList<label, 5> list5{0, 1, 2, 3, 4};
Info<< "list5: " << list5 << nl; Info<< "list5: " << list5 << nl;
{
const FixedList<label, 2> indices({3, 1});
FixedList<label, 2> list4b(list4, indices);
Info<< "subset " << list4 << " with " << indices << " -> "
<< list4b << nl;
}
List<FixedList<label, 2>> list6{{0, 1}, {2, 3}}; List<FixedList<label, 2>> list6{{0, 1}, {2, 3}};
Info<< "list6: " << list6 << nl; Info<< "list6: " << list6 << nl;

View File

@ -152,7 +152,7 @@ public:
//- Construct and initialize all entries to zero //- Construct and initialize all entries to zero
inline explicit FixedList(const Foam::zero); inline explicit FixedList(const Foam::zero);
//- Copy construct from C-array //- Copy construct from C-array (deprecated)
inline explicit FixedList(const T list[N]); inline explicit FixedList(const T list[N]);
//- Copy construct //- Copy construct
@ -162,25 +162,28 @@ public:
//- list elements //- list elements
inline FixedList(FixedList<T, N>&& list); inline FixedList(FixedList<T, N>&& list);
//- Construct given begin/end iterators //- Construct from an initializer list. Runtime size check
// Uses std::distance when verifying the size.
template<class InputIterator>
inline FixedList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list
inline FixedList(std::initializer_list<T> list); inline FixedList(std::initializer_list<T> list);
//- Construct from UList //- Construct from UList. Runtime size check
inline explicit FixedList(const UList<T>& list); inline explicit FixedList(const UList<T>& list);
//- Copy construct from a subset of the input //- Copy construct from a subset of the input. No size check
template<unsigned AnyNum>
inline FixedList
(
const FixedList<T, AnyNum>& list,
const FixedList<label, N>& indices
);
//- Copy construct from a subset of the input. No size check
inline FixedList inline FixedList
( (
const UList<T>& list, const UList<T>& list,
const FixedList<label, N>& indices const FixedList<label, N>& indices
); );
//- Construct from SLList //- Construct from SLList. Runtime size check
inline explicit FixedList(const SLList<T>& list); inline explicit FixedList(const SLList<T>& list);
//- Construct from Istream //- Construct from Istream

View File

@ -28,7 +28,6 @@ License
#include "UList.H" #include "UList.H"
#include "SLList.H" #include "SLList.H"
#include <type_traits>
#include <utility> #include <utility>
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -86,24 +85,6 @@ inline Foam::FixedList<T, N>::FixedList(FixedList<T, N>&& list)
} }
template<class T, unsigned N>
template<class InputIterator>
inline Foam::FixedList<T, N>::FixedList
(
InputIterator begIter,
InputIterator endIter
)
{
checkSize(std::distance(begIter, endIter));
for (unsigned i=0; i<N; ++i)
{
v_[i] = *begIter;
++begIter;
}
}
template<class T, unsigned N> template<class T, unsigned N>
inline Foam::FixedList<T, N>::FixedList(std::initializer_list<T> list) inline Foam::FixedList<T, N>::FixedList(std::initializer_list<T> list)
{ {
@ -130,6 +111,21 @@ inline Foam::FixedList<T, N>::FixedList(const UList<T>& list)
} }
template<class T, unsigned N>
template<unsigned AnyNum>
inline Foam::FixedList<T, N>::FixedList
(
const FixedList<T, AnyNum>& list,
const FixedList<label, N>& indices
)
{
for (unsigned i=0; i<N; ++i)
{
v_[i] = list[indices[i]];
}
}
template<class T, unsigned N> template<class T, unsigned N>
inline Foam::FixedList<T, N>::FixedList inline Foam::FixedList<T, N>::FixedList
( (