mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: copy construct FixedList from fixed subset of input
- remove construct from two iterators (#2083)
This commit is contained in:
@ -280,16 +280,24 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
List<label> list3{0, 1, 2, 3};
|
||||
FixedList<label, 4> list4(list3.begin(), list3.end());
|
||||
FixedList<label, 4> list4(list3);
|
||||
Info<< "list3: " << list3 << nl
|
||||
<< "list4: " << list4 << nl;
|
||||
|
||||
list4 = {1, 2, 3, 5};
|
||||
list4 = {1, 20, 3, 40};
|
||||
Info<< "list4: " << list4 << nl;
|
||||
|
||||
FixedList<label, 5> list5{0, 1, 2, 3, 4};
|
||||
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}};
|
||||
Info<< "list6: " << list6 << nl;
|
||||
|
||||
|
||||
@ -152,7 +152,7 @@ public:
|
||||
//- Construct and initialize all entries to 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]);
|
||||
|
||||
//- Copy construct
|
||||
@ -162,25 +162,28 @@ public:
|
||||
//- list elements
|
||||
inline FixedList(FixedList<T, N>&& list);
|
||||
|
||||
//- Construct given begin/end iterators
|
||||
// Uses std::distance when verifying the size.
|
||||
template<class InputIterator>
|
||||
inline FixedList(InputIterator begIter, InputIterator endIter);
|
||||
|
||||
//- Construct from an initializer list
|
||||
//- Construct from an initializer list. Runtime size check
|
||||
inline FixedList(std::initializer_list<T> list);
|
||||
|
||||
//- Construct from UList
|
||||
//- Construct from UList. Runtime size check
|
||||
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
|
||||
(
|
||||
const UList<T>& list,
|
||||
const FixedList<label, N>& indices
|
||||
);
|
||||
|
||||
//- Construct from SLList
|
||||
//- Construct from SLList. Runtime size check
|
||||
inline explicit FixedList(const SLList<T>& list);
|
||||
|
||||
//- Construct from Istream
|
||||
|
||||
@ -28,7 +28,6 @@ License
|
||||
|
||||
#include "UList.H"
|
||||
#include "SLList.H"
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
// * * * * * * * * * * * * * 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>
|
||||
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>
|
||||
inline Foam::FixedList<T, N>::FixedList
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user