diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 426efed774..6692039ca0 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -369,7 +369,7 @@ Foam::List::List(std::initializer_list list) template Foam::List::List(List&& list) : - UList(nullptr, 0) + UList() { // Can use transfer or swap to manage content transfer(list); @@ -380,7 +380,7 @@ template template Foam::List::List(DynamicList&& list) : - UList(nullptr, 0) + UList() { transfer(list); } @@ -389,7 +389,7 @@ Foam::List::List(DynamicList&& list) template Foam::List::List(SortableList&& list) : - UList(nullptr, 0) + UList() { transfer(list); } @@ -398,7 +398,7 @@ Foam::List::List(SortableList&& list) template Foam::List::List(SLList&& list) : - UList(nullptr, 0) + UList() { operator=(std::move(list)); } @@ -531,18 +531,33 @@ void Foam::List::operator=(const SLList& list) if (len) { - List_ACCESS(T, (*this), vp); + T* iter = this->begin(); - label i = 0; - for (auto iter = list.cbegin(); iter != list.cend(); ++iter) + for (const T& val : list) { - vp[i] = *iter; - ++i; + *iter = val; + ++iter; } } } +template +template +void Foam::List::operator=(const FixedList& list) +{ + reAlloc(label(N)); + + T* iter = this->begin(); + + for (const T& val : list) + { + *iter = val; + ++iter; + } +} + + template template void Foam::List::operator=(const IndirectListBase& list) @@ -572,13 +587,12 @@ void Foam::List::operator=(std::initializer_list list) if (len) { - List_ACCESS(T, (*this), vp); + T* iter = this->begin(); - label i = 0; for (const T& val : list) { - vp[i] = val; - ++i; + *iter = val; + ++iter; } } } @@ -614,18 +628,16 @@ void Foam::List::operator=(SortableList&& list) template void Foam::List::operator=(SLList&& list) { - const label len = list.size(); + label len = list.size(); reAlloc(len); - if (len) - { - List_ACCESS(T, (*this), vp); + T* iter = this->begin(); - for (label i = 0; i < len; ++i) - { - vp[i] = std::move(list.removeHead()); - } + while (len--) + { + *iter = std::move(list.removeHead()); + ++iter; } list.clear(); diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index b9ae065c13..9b5d43a609 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -52,7 +52,7 @@ SourceFiles namespace Foam { -// Forward declarations +// Forward Declarations class Istream; class Ostream; @@ -268,6 +268,10 @@ public: template void operator=(const IndirectListBase& list); + //- Copy assignment from FixedList + template + void operator=(const FixedList& list); + //- Assignment to an initializer list void operator=(std::initializer_list list); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 1d17f2dc5f..6564cf6642 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -160,8 +160,11 @@ const Foam::UList Foam::UList::operator[](const labelRange& range) const template void Foam::UList::operator=(const T& val) { + const label len = this->size(); + List_ACCESS(T, (*this), vp); - List_FOR_ALL((*this), i) + + for (label i=0; i < len; ++i) { vp[i] = val; } @@ -171,8 +174,11 @@ void Foam::UList::operator=(const T& val) template void Foam::UList::operator=(const zero) { + const label len = this->size(); + List_ACCESS(T, (*this), vp); - List_FOR_ALL((*this), i) + + for (label i=0; i < len; ++i) { vp[i] = Zero; }