Commit 3f4f05b6 authored by Henry Weller's avatar Henry Weller
Browse files

Map, SortableList: Added constructors from and assignment to initializer list

Patch based on contribution from Mattijs Janssens
Resolves http://bugs.openfoam.org/view.php?id=2276
parent ec9883f3
......@@ -91,6 +91,11 @@ public:
HashTable<T, label, Hash<label>>(map)
{}
//- Construct from an initializer list
Map(std::initializer_list<Tuple2<label, T>> map)
:
HashTable<T, label, Hash<label>>(map)
{}
};
......
......@@ -72,6 +72,15 @@ Foam::SortableList<T>::SortableList(const SortableList<T>& lst)
{}
template<class T>
Foam::SortableList<T>::SortableList(std::initializer_list<T> values)
:
List<T>(values)
{
sort();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -138,20 +147,27 @@ inline void Foam::SortableList<T>::operator=(const T& t)
template<class T>
inline void Foam::SortableList<T>::operator=(const UList<T>& rhs)
inline void Foam::SortableList<T>::operator=(const UList<T>& lst)
{
List<T>::operator=(rhs);
List<T>::operator=(lst);
indices_.clear();
}
template<class T>
inline void Foam::SortableList<T>::operator=(const SortableList<T>& rhs)
inline void Foam::SortableList<T>::operator=(const SortableList<T>& lst)
{
List<T>::operator=(rhs);
indices_ = rhs.indices();
List<T>::operator=(lst);
indices_ = lst.indices();
}
template<class T>
inline void Foam::SortableList<T>::operator=(std::initializer_list<T> lst)
{
List<T>::operator=(lst);
sort();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //
......@@ -67,33 +67,36 @@ public:
//- Null constructor, sort later (eg, after assignment or transfer)
SortableList();
//- Construct from UList, sorting immediately.
//- Construct from UList, sorting immediately
explicit SortableList(const UList<T>&);
//- Construct from transferred List, sorting immediately.
//- Construct from transferred List, sorting immediately
explicit SortableList(const Xfer<List<T>>&);
//- Construct given size. Sort later on.
//- Construct given size. Sort later on
// The indices remain empty until the list is sorted
explicit SortableList(const label size);
//- Construct given size and initial value. Sort later on.
//- Construct given size and initial value. Sort later on
// The indices remain empty until the list is sorted
SortableList(const label size, const T&);
//- Construct as copy.
//- Construct as copy
SortableList(const SortableList<T>&);
//- Construct from an initializer list, sorting immediately
SortableList(std::initializer_list<T>);
// Member Functions
//- Return the list of sorted indices. Updated every sort.
//- Return the list of sorted indices. Updated every sort
const labelList& indices() const
{
return indices_;
}
//- Return non-const access to the sorted indices. Updated every sort.
//- Return non-const access to the sorted indices. Updated every sort
labelList& indices()
{
return indices_;
......@@ -121,12 +124,14 @@ public:
//- Assignment of all entries to the given value
inline void operator=(const T&);
//- Assignment to UList operator. Takes linear time.
//- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>&);
//- Assignment operator. Takes linear time.
//- Assignment operator. Takes linear time
inline void operator=(const SortableList<T>&);
//- Assignment to an initializer list
void operator=(std::initializer_list<T>);
};
......
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