Commit 7a299ed7 authored by Henry Weller's avatar Henry Weller
Browse files

FixedList: Add constructors from iterators and C++11 initializer_list using...

FixedList: Add constructors from iterators and C++11 initializer_list using C++11 constructor delegation
parent 3c423d64
......@@ -71,6 +71,17 @@ int main(int argc, char *argv[])
Info<< "list: " << list << nl
<< "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::myProcNo() != Pstream::masterNo())
......
......@@ -43,6 +43,7 @@ SourceFiles
#include "Hash.H"
#include "autoPtr.H"
#include <type_traits>
#include <initializer_list>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -100,6 +101,7 @@ public:
) const;
};
// Static Member Functions
//- Return a null FixedList
......@@ -111,11 +113,18 @@ public:
//- Null constructor.
inline FixedList();
//- Construct from value
explicit inline FixedList(const T&);
//- Construct from C-array.
explicit inline FixedList(const T v[Size]);
//- Construct from value
explicit inline FixedList(const T&);
//- Construct given start and end iterators
template<class InputIterator>
inline FixedList(InputIterator first, InputIterator last);
//- Construct from brace-enclosed values
inline FixedList(std::initializer_list<T>);
//- Construct from UList.
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>
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>
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++)
{
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>
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());
label i = 0;
for
(
typename SLList<T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
typename SLList<T>::const_iterator iter = lst.begin();
for (unsigned i=0; i<Size; i++)
{
operator[](i++) = iter();
v_[i] = *iter++;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment