mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
FixedList: Add constructors from iterators and C++11 initializer_list using C++11 constructor delegation
This commit is contained in:
@ -71,6 +71,17 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "list: " << list << nl
|
Info<< "list: " << list << nl
|
||||||
<< "list2: " << list2 << endl;
|
<< "list2: " << list2 << endl;
|
||||||
|
|
||||||
|
List<label> list3{0, 1, 2, 3};
|
||||||
|
FixedList<label, 4> list4(list3.begin(), list3.end());
|
||||||
|
Info<< "list3: " << list3 << nl
|
||||||
|
<< "list4: " << list4 << endl;
|
||||||
|
|
||||||
|
FixedList<label, 5> list5{0, 1, 2, 3, 4};
|
||||||
|
Info<< "list5: " << list5 << endl;
|
||||||
|
|
||||||
|
List<FixedList<label, 2>> list6{{0, 1}, {2, 3}};
|
||||||
|
Info<< "list6: " << list6 << endl;
|
||||||
|
|
||||||
if (Pstream::parRun())
|
if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
if (Pstream::myProcNo() != Pstream::masterNo())
|
if (Pstream::myProcNo() != Pstream::masterNo())
|
||||||
|
|||||||
@ -43,6 +43,7 @@ SourceFiles
|
|||||||
#include "Hash.H"
|
#include "Hash.H"
|
||||||
#include "autoPtr.H"
|
#include "autoPtr.H"
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -100,6 +101,7 @@ public:
|
|||||||
) const;
|
) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Static Member Functions
|
// Static Member Functions
|
||||||
|
|
||||||
//- Return a null FixedList
|
//- Return a null FixedList
|
||||||
@ -111,11 +113,18 @@ public:
|
|||||||
//- Null constructor.
|
//- Null constructor.
|
||||||
inline FixedList();
|
inline FixedList();
|
||||||
|
|
||||||
|
//- Construct from value
|
||||||
|
explicit inline FixedList(const T&);
|
||||||
|
|
||||||
//- Construct from C-array.
|
//- Construct from C-array.
|
||||||
explicit inline FixedList(const T v[Size]);
|
explicit inline FixedList(const T v[Size]);
|
||||||
|
|
||||||
//- Construct from value
|
//- Construct given start and end iterators
|
||||||
explicit inline FixedList(const T&);
|
template<class InputIterator>
|
||||||
|
inline FixedList(InputIterator first, InputIterator last);
|
||||||
|
|
||||||
|
//- Construct from brace-enclosed values
|
||||||
|
inline FixedList(std::initializer_list<T>);
|
||||||
|
|
||||||
//- Construct from UList.
|
//- Construct from UList.
|
||||||
explicit inline FixedList(const UList<T>&);
|
explicit inline FixedList(const UList<T>&);
|
||||||
|
|||||||
@ -34,6 +34,16 @@ inline Foam::FixedList<T, Size>::FixedList()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, unsigned Size>
|
||||||
|
inline Foam::FixedList<T, Size>::FixedList(const T& t)
|
||||||
|
{
|
||||||
|
for (unsigned i=0; i<Size; i++)
|
||||||
|
{
|
||||||
|
v_[i] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, unsigned Size>
|
template<class T, unsigned Size>
|
||||||
inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
|
inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
|
||||||
{
|
{
|
||||||
@ -45,15 +55,30 @@ inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
|
|||||||
|
|
||||||
|
|
||||||
template<class T, unsigned Size>
|
template<class T, unsigned Size>
|
||||||
inline Foam::FixedList<T, Size>::FixedList(const T& t)
|
template<class InputIterator>
|
||||||
|
Foam::FixedList<T, Size>::FixedList
|
||||||
|
(
|
||||||
|
InputIterator first,
|
||||||
|
InputIterator last
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
checkSize(std::distance(first, last));
|
||||||
|
|
||||||
|
InputIterator iter = first;
|
||||||
for (unsigned i=0; i<Size; i++)
|
for (unsigned i=0; i<Size; i++)
|
||||||
{
|
{
|
||||||
v_[i] = t;
|
v_[i] = *iter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, unsigned Size>
|
||||||
|
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
|
||||||
|
:
|
||||||
|
FixedList<T, Size>(lst.begin(), lst.end())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T, unsigned Size>
|
template<class T, unsigned Size>
|
||||||
inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
|
inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
|
||||||
{
|
{
|
||||||
@ -71,15 +96,10 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
|
|||||||
{
|
{
|
||||||
checkSize(lst.size());
|
checkSize(lst.size());
|
||||||
|
|
||||||
label i = 0;
|
|
||||||
for
|
|
||||||
(
|
|
||||||
typename SLList<T>::const_iterator iter = lst.begin();
|
typename SLList<T>::const_iterator iter = lst.begin();
|
||||||
iter != lst.end();
|
for (unsigned i=0; i<Size; i++)
|
||||||
++iter
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
operator[](i++) = iter();
|
v_[i] = *iter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user