STYLE: make null constructed lists constexpr, noexcept

- can assist the compiler in producing tighter code.
This commit is contained in:
Mark Olesen 2018-03-19 13:53:28 +01:00
parent ca15b5779d
commit 4cb763f9d2
27 changed files with 549 additions and 450 deletions

View File

@ -115,7 +115,7 @@ public:
// Constructors
//- Construct null
inline DynamicList();
inline constexpr DynamicList() noexcept;
//- Construct an empty list with given reserve size.
explicit inline DynamicList(const label nElem);

View File

@ -56,7 +56,7 @@ inline void Foam::DynamicList<T, SizeMin>::assignDynList
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::DynamicList<T, SizeMin>::DynamicList()
inline constexpr Foam::DynamicList<T, SizeMin>::DynamicList() noexcept
:
capacity_(0)
{}

View File

@ -37,11 +37,11 @@ Foam::label Foam::FixedList<T, Size>::find
{
if (start >= 0)
{
List_CONST_ACCESS(T, *this, lst);
List_CONST_ACCESS(T, *this, list);
for (label i = start; i < label(Size); ++i)
{
if (lst[i] == val)
if (list[i] == val)
{
return i;
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,14 +40,16 @@ SourceFiles
#include "bool.H"
#include "label.H"
#include "uLabel.H"
#include "zero.H"
#include "Hash.H"
#include "autoPtr.H"
#include "Swap.H"
#include "SLListFwd.H"
#include <type_traits>
#include <initializer_list>
#include <iterator>
#include <type_traits>
#include <limits>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -76,7 +78,7 @@ class FixedList
{
static_assert
(
Size && Size <= INT_MAX,
Size && Size <= std::numeric_limits<int>::max(),
"Size must be positive (non-zero) and also fit as a signed value"
);
@ -90,10 +92,13 @@ protected:
// Protected Member Functions
//- True if there are two or more entries and all entries have
// identical values.
inline bool uniform() const;
//- Write the FixedList with its compound type
void writeEntry(Ostream& os) const;
public:
// STL type definitions
@ -139,7 +144,7 @@ public:
{
inline unsigned operator()
(
const FixedList<T, Size>& lst,
const FixedList<T, Size>& list,
unsigned seed = 0
) const;
};
@ -156,18 +161,21 @@ public:
//- Null constructor
inline FixedList() = default;
//- Construct from value
//- Construct and initialize all entries to given value
explicit inline FixedList(const T& val);
//- Construct and initialize all entries to zero
explicit inline FixedList(const zero);
//- Copy construct from C-array
explicit inline FixedList(const T lst[Size]);
explicit inline FixedList(const T list[Size]);
//- Copy constructor
inline FixedList(const FixedList<T, Size>& lst);
inline FixedList(const FixedList<T, Size>& list);
//- Move construct by using move assignment for the individual
//- list elements
inline FixedList(FixedList<T, Size>&& lst);
inline FixedList(FixedList<T, Size>&& list);
//- Construct given begin/end iterators
// Uses std::distance when verifying the size.
@ -175,13 +183,13 @@ public:
inline FixedList(InputIterator begIter, InputIterator endIter);
//- Construct from an initializer list
inline FixedList(std::initializer_list<T> lst);
inline FixedList(std::initializer_list<T> list);
//- Construct from UList
explicit inline FixedList(const UList<T>& lst);
explicit inline FixedList(const UList<T>& list);
//- Construct from SLList
explicit inline FixedList(const SLList<T>& lst);
explicit inline FixedList(const SLList<T>& list);
//- Construct from Istream
FixedList(Istream& is);
@ -250,7 +258,7 @@ public:
inline void checkIndex(const label i) const;
// Search
// Search
//- Find index of the first occurence of the value.
// Linear search.
@ -261,7 +269,7 @@ public:
inline bool found(const T& val, const label start=0) const;
// Edit
// Edit
//- Dummy resize function
// needed to make FixedList consistent with List
@ -285,7 +293,7 @@ public:
//- Transfer by swapping using a move assignment for the content
//- of the individual list elements
inline void transfer(FixedList<T, Size>& lst);
inline void transfer(FixedList<T, Size>& list);
// Member operators
@ -297,25 +305,25 @@ public:
inline const T& operator[](const label i) const;
//- Assignment to array operator. Takes linear time
inline void operator=(const T lst[Size]);
inline void operator=(const T list[Size]);
//- Assignment to UList operator. Takes linear time
inline void operator=(const UList<T>& lst);
inline void operator=(const UList<T>& list);
//- Assignment to SLList operator. Takes linear time
inline void operator=(const SLList<T>& lst);
inline void operator=(const SLList<T>& list);
//- Assignment to an initializer list. Takes linear time
inline void operator=(std::initializer_list<T> lst);
inline void operator=(std::initializer_list<T> list);
//- Assignment of all entries to the given value
inline void operator=(const T& val);
//- Copy assignment
inline void operator=(const FixedList<T, Size>& lst);
inline void operator=(const FixedList<T, Size>& list);
//- Move assignment
inline void operator=(FixedList<T, Size>&& lst);
inline void operator=(FixedList<T, Size>&& list);
// Random access iterator (non-const)
@ -378,7 +386,7 @@ public:
inline bool empty() const;
//- Swap lists by swapping the content of the individual list elements
inline void swap(FixedList<T, Size>& lst);
inline void swap(FixedList<T, Size>& list);
// STL member operators
@ -421,14 +429,14 @@ public:
friend Istream& operator>> <T, Size>
(
Istream& is,
FixedList<T, Size>& lst
FixedList<T, Size>& list
);
//- Write to Ostream, as per writeList() with shortListLen=10
friend Ostream& operator<< <T, Size>
(
Ostream& os,
const FixedList<T, Size>& lst
const FixedList<T, Size>& list
);
};

View File

@ -30,6 +30,30 @@ License
#include <type_traits>
#include <utility>
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class T, unsigned Size>
inline bool Foam::FixedList<T, Size>::uniform() const
{
if (Size > 1)
{
const T& val = first();
for (unsigned i=1; i<Size; ++i)
{
if (val != (*this)[i])
{
return false;
}
}
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, unsigned Size>
@ -43,31 +67,41 @@ inline Foam::FixedList<T, Size>::FixedList(const T& val)
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T lst[Size])
inline Foam::FixedList<T, Size>::FixedList(const zero)
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst[i];
v_[i] = Zero;
}
}
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
inline Foam::FixedList<T, Size>::FixedList(const T list[Size])
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst.v_[i];
v_[i] = list[i];
}
}
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(FixedList<T, Size>&& lst)
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& list)
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = std::move(lst.v_[i]);
v_[i] = list.v_[i];
}
}
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(FixedList<T, Size>&& list)
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = std::move(list.v_[i]);
}
}
@ -92,11 +126,11 @@ inline Foam::FixedList<T, Size>::FixedList
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> list)
{
checkSize(lst.size());
checkSize(list.size());
auto iter = lst.begin();
auto iter = list.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
@ -106,23 +140,23 @@ inline Foam::FixedList<T, Size>::FixedList(std::initializer_list<T> lst)
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
inline Foam::FixedList<T, Size>::FixedList(const UList<T>& list)
{
checkSize(lst.size());
checkSize(list.size());
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst[i];
v_[i] = list[i];
}
}
template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& list)
{
checkSize(lst.size());
checkSize(list.size());
auto iter = lst.begin();
auto iter = list.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
@ -256,21 +290,21 @@ inline void Foam::FixedList<T, Size>::setSize(const label n)
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& lst)
inline void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& list)
{
for (unsigned i=0; i<Size; ++i)
{
Foam::Swap(v_[i], lst.v_[i]);
Foam::Swap(v_[i], list.v_[i]);
}
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::transfer(FixedList<T, Size>& lst)
inline void Foam::FixedList<T, Size>::transfer(FixedList<T, Size>& list)
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = std::move(lst[i]);
v_[i] = std::move(list[i]);
}
}
@ -342,31 +376,31 @@ inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
inline void Foam::FixedList<T, Size>::operator=(const T list[Size])
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst[i];
v_[i] = list[i];
}
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const UList<T>& lst)
inline void Foam::FixedList<T, Size>::operator=(const UList<T>& list)
{
checkSize(lst.size());
checkSize(list.size());
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst[i];
v_[i] = list[i];
}
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& list)
{
checkSize(lst.size());
checkSize(list.size());
typename SLList<T>::const_iterator iter = lst.begin();
auto iter = list.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
@ -375,11 +409,11 @@ inline void Foam::FixedList<T, Size>::operator=(const SLList<T>& lst)
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(std::initializer_list<T> lst)
inline void Foam::FixedList<T, Size>::operator=(std::initializer_list<T> list)
{
checkSize(lst.size());
checkSize(list.size());
auto iter = lst.begin();
auto iter = list.begin();
for (unsigned i=0; i<Size; ++i)
{
v_[i] = *iter;
@ -397,22 +431,22 @@ inline void Foam::FixedList<T, Size>::operator=(const T& val)
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(const FixedList<T, Size>& lst)
inline void Foam::FixedList<T, Size>::operator=(const FixedList<T, Size>& list)
{
for (unsigned i=0; i<Size; ++i)
{
v_[i] = lst.v_[i];
v_[i] = list.v_[i];
}
}
template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::operator=(FixedList<T, Size>&& lst)
inline void Foam::FixedList<T, Size>::operator=(FixedList<T, Size>&& list)
{
// No significant speedup observed for copy assignment on simple types,
// use move assignment for generality with more complex types
for (unsigned i=0; i<Size; ++i)
{
v_[i] = std::move(lst.v_[i]);
v_[i] = std::move(list.v_[i]);
}
}
@ -540,14 +574,14 @@ template<class T, unsigned Size>
template<class HashT>
inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
(
const FixedList<T, Size>& lst,
const FixedList<T, Size>& list,
unsigned seed
) const
{
if (contiguous<T>())
{
// Hash directly
return Hasher(lst.v_, sizeof(lst.v_), seed);
return Hasher(list.v_, sizeof(list.v_), seed);
}
// Hash incrementally
@ -555,7 +589,7 @@ inline unsigned Foam::FixedList<T, Size>::Hash<HashT>::operator()
for (unsigned i=0; i<Size; ++i)
{
val = HashT()(lst[i], val);
val = HashT()(list[i], val);
}
return val;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,35 +67,16 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
const label shortListLen
) const
{
const FixedList<T, Size>& lst = *this;
const FixedList<T, Size>& list = *this;
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (Size > 1 && contiguous<T>());
if (uniform)
if (contiguous<T>() && list.uniform())
{
for (unsigned i=0; i<Size; ++i)
{
if (lst[i] != lst[0])
{
uniform = false;
break;
}
}
}
// Two or more entries, and all entries have identical values.
if (uniform)
{
// Write size (so it is valid dictionary entry) and start delimiter
os << Size << token::BEGIN_BLOCK;
// Contents
os << lst[0];
// End delimiter
os << token::END_BLOCK;
os << Size << token::BEGIN_BLOCK << list[0] << token::END_BLOCK;
}
else if
(
@ -110,7 +91,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
for (unsigned i=0; i<Size; ++i)
{
if (i) os << token::SPACE;
os << lst[i];
os << list[i];
}
// End delimiter
@ -124,7 +105,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
// Contents
for (unsigned i=0; i<Size; ++i)
{
os << lst[i] << nl;
os << list[i] << nl;
}
// End delimiter
@ -136,7 +117,7 @@ Foam::Ostream& Foam::FixedList<T, Size>::writeList
// Binary, contiguous
// write(...) includes surrounding start/end delimiters
os.write(reinterpret_cast<const char*>(lst.cdata()), Size*sizeof(T));
os.write(reinterpret_cast<const char*>(list.cdata()), Size*sizeof(T));
}
os.check(FUNCTION_NAME);
@ -154,7 +135,7 @@ Foam::FixedList<T, Size>::FixedList(Istream& is)
template<class T, unsigned Size>
Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& list)
{
is.fatalCheck(FUNCTION_NAME);
@ -169,7 +150,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
if (firstToken.isCompound())
{
lst = dynamicCast<token::Compound<List<T>>>
list = dynamicCast<token::Compound<List<T>>>
(
firstToken.transferCompoundToken(is)
);
@ -179,7 +160,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
const label len = firstToken.labelToken();
// List lengths must match
lst.checkSize(len);
list.checkSize(len);
}
else if (!firstToken.isPunctuation())
{
@ -202,7 +183,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
{
for (unsigned i=0; i<Size; ++i)
{
is >> lst[i];
is >> list[i];
is.fatalCheck
(
@ -224,7 +205,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
for (unsigned i=0; i<Size; ++i)
{
lst[i] = element; // Copy the value
list[i] = element; // Copy the value
}
}
@ -235,7 +216,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
{
// Binary and contiguous
is.read(reinterpret_cast<char*>(lst.data()), Size*sizeof(T));
is.read(reinterpret_cast<char*>(list.data()), Size*sizeof(T));
is.fatalCheck
(
@ -249,9 +230,9 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& lst)
template<class T, unsigned Size>
Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& lst)
Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& list)
{
return lst.writeList(os, 10);
return list.writeList(os, 10);
}

View File

@ -29,38 +29,38 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
Foam::PtrList<T>::PtrList(const PtrList<T>& lst)
Foam::PtrList<T>::PtrList(const PtrList<T>& list)
:
UPtrList<T>(lst.size())
UPtrList<T>(list.size())
{
const label len = this->size();
for (label i=0; i<len; ++i)
{
this->ptrs_[i] = (lst[i]).clone().ptr();
this->ptrs_[i] = (list[i]).clone().ptr();
}
}
template<class T>
template<class CloneArg>
Foam::PtrList<T>::PtrList(const PtrList<T>& lst, const CloneArg& cloneArg)
Foam::PtrList<T>::PtrList(const PtrList<T>& list, const CloneArg& cloneArg)
:
UPtrList<T>(lst.size())
UPtrList<T>(list.size())
{
const label len = this->size();
for (label i=0; i<len; ++i)
{
this->ptrs_[i] = (lst[i]).clone(cloneArg).ptr();
this->ptrs_[i] = (list[i]).clone(cloneArg).ptr();
}
}
template<class T>
Foam::PtrList<T>::PtrList(PtrList<T>& lst, bool reuse)
Foam::PtrList<T>::PtrList(PtrList<T>& list, bool reuse)
:
UPtrList<T>(lst, reuse)
UPtrList<T>(list, reuse)
{
if (!reuse)
{
@ -68,21 +68,21 @@ Foam::PtrList<T>::PtrList(PtrList<T>& lst, bool reuse)
for (label i=0; i<len; ++i)
{
this->ptrs_[i] = (lst[i]).clone().ptr();
this->ptrs_[i] = (list[i]).clone().ptr();
}
}
}
template<class T>
Foam::PtrList<T>::PtrList(const SLPtrList<T>& lst)
Foam::PtrList<T>::PtrList(const SLPtrList<T>& list)
:
UPtrList<T>(lst.size())
UPtrList<T>(list.size())
{
if (lst.size())
if (list.size())
{
label i = 0;
for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
for (auto iter = list.cbegin(); iter != list.cend(); ++iter)
{
this->ptrs_[i++] = (*iter).clone().ptr();
}
@ -128,7 +128,7 @@ void Foam::PtrList<T>::clear()
template<class T>
void Foam::PtrList<T>::setSize(const label newLen)
void Foam::PtrList<T>::resize(const label newLen)
{
if (newLen <= 0)
{
@ -150,7 +150,7 @@ void Foam::PtrList<T>::setSize(const label newLen)
}
// Any new elements are initialized to nullptr.
this->ptrs_.setSize(newLen, reinterpret_cast<T*>(0));
this->ptrs_.resize(newLen, reinterpret_cast<T*>(0));
}
}
@ -158,9 +158,9 @@ void Foam::PtrList<T>::setSize(const label newLen)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
void Foam::PtrList<T>::operator=(const PtrList<T>& lst)
void Foam::PtrList<T>::operator=(const PtrList<T>& list)
{
if (this == &lst)
if (this == &list)
{
FatalErrorInFunction
<< "attempted assignment to self for type " << typeid(T).name()
@ -168,17 +168,17 @@ void Foam::PtrList<T>::operator=(const PtrList<T>& lst)
}
const label oldLen = this->size();
const label newLen = lst.size();
const label newLen = list.size();
// Truncate (frees old pointers) or extend the length
setSize(newLen);
resize(newLen);
if (newLen < oldLen)
{
// Copy values for existing entries
for (label i=0; i<newLen; ++i)
{
(*this)[i] = lst[i];
(*this)[i] = list[i];
}
}
else
@ -186,13 +186,13 @@ void Foam::PtrList<T>::operator=(const PtrList<T>& lst)
// Copy values for existing entries
for (label i=0; i<oldLen; ++i)
{
(*this)[i] = lst[i];
(*this)[i] = list[i];
}
// Clone pointers for new entries
for (label i=oldLen; i<newLen; ++i)
{
this->ptrs_[i] = (lst[i]).clone().ptr();
this->ptrs_[i] = (list[i]).clone().ptr();
}
}
}

View File

@ -83,26 +83,26 @@ public:
// Constructors
//- Construct null
PtrList() = default;
inline constexpr PtrList() noexcept;
//- Construct with specified size, each element initialized to nullptr
explicit inline PtrList(const label nElem);
//- Copy construct using 'clone()' method on each element
PtrList(const PtrList<T>& lst);
PtrList(const PtrList<T>& list);
//- Move construct
inline PtrList(PtrList<T>&& lst);
inline PtrList(PtrList<T>&& list);
//- Copy construct with additional argument for 'clone()'
template<class CloneArg>
PtrList(const PtrList<T>& lst, const CloneArg& cloneArg);
PtrList(const PtrList<T>& list, const CloneArg& cloneArg);
//- Construct as copy or re-use as specified
PtrList(PtrList<T>& lst, bool reuse);
PtrList(PtrList<T>& list, bool reuse);
//- Construct as copy of SLPtrList<T>
explicit PtrList(const SLPtrList<T>& lst);
explicit PtrList(const SLPtrList<T>& list);
//- Construct from Istream using given Istream constructor class
template<class INew>
@ -123,11 +123,11 @@ public:
//- Reset size of PtrList.
// New entries are initialized to nullptr, removed entries are deleted
void setSize(const label newLen);
void resize(const label newLen);
//- Reset size of PtrList.
// New entries are initialized to nullptr, removed entries are deleted
inline void resize(const label newLen);
inline void setSize(const label newLen);
//- Append an element at the end of the list
using UPtrList<T>::append;
@ -139,7 +139,7 @@ public:
inline void append(const tmp<T>& tptr);
//- Transfer into this list and annul the argument list
inline void transfer(PtrList<T>& lst);
inline void transfer(PtrList<T>& list);
//- Return true if element is set (ie, not a nullptr)
inline bool set(const label i) const;
@ -159,16 +159,16 @@ public:
//- Copy assignment.
// For existing list entries, values are copied from the list.
// For new list entries, pointers are cloned from the list.
void operator=(const PtrList<T>& lst);
void operator=(const PtrList<T>& list);
//- Move assignment
inline void operator=(PtrList<T>&& lst);
inline void operator=(PtrList<T>&& list);
// IOstream operator
//- Read PtrList from Istream, discarding contents of existing PtrList
friend Istream& operator>> <T>(Istream& is, PtrList<T>& lst);
friend Istream& operator>> <T>(Istream& is, PtrList<T>& list);
};

View File

@ -28,6 +28,13 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
inline constexpr Foam::PtrList<T>::PtrList() noexcept
:
UPtrList<T>()
{}
template<class T>
inline Foam::PtrList<T>::PtrList(const label nElem)
:
@ -36,18 +43,18 @@ inline Foam::PtrList<T>::PtrList(const label nElem)
template<class T>
inline Foam::PtrList<T>::PtrList(PtrList<T>&& lst)
inline Foam::PtrList<T>::PtrList(PtrList<T>&& list)
:
UPtrList<T>(std::move(lst))
UPtrList<T>(std::move(list))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline void Foam::PtrList<T>::resize(const label newLen)
inline void Foam::PtrList<T>::setSize(const label newLen)
{
this->setSize(newLen);
this->resize(newLen);
}
@ -68,16 +75,14 @@ inline void Foam::PtrList<T>::append(const tmp<T>& tptr)
template<class T>
inline bool Foam::PtrList<T>::set(const label i) const
{
return this->ptrs_[i] != nullptr;
return UPtrList<T>::set(i);
}
template<class T>
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
{
autoPtr<T> old(this->ptrs_[i]);
this->ptrs_[i] = ptr;
return old;
return autoPtr<T>(UPtrList<T>::set(i, ptr));
}
@ -104,20 +109,19 @@ inline Foam::autoPtr<T> Foam::PtrList<T>::set
template<class T>
inline void Foam::PtrList<T>::transfer(PtrList<T>& lst)
inline void Foam::PtrList<T>::transfer(PtrList<T>& list)
{
this->clear();
UPtrList<T>::swap(lst);
UPtrList<T>::transfer(list);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline void Foam::PtrList<T>::operator=(PtrList<T>&& lst)
inline void Foam::PtrList<T>::operator=(PtrList<T>&& list)
{
this->clear();
this->swap(lst);
this->transfer(list);
}

View File

@ -28,7 +28,10 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::SortableList<T>::SortableList()
inline constexpr Foam::SortableList<T>::SortableList() noexcept
:
List<T>(),
indices_()
{}

View File

@ -65,7 +65,7 @@ public:
// Constructors
//- Null constructor, sort later (eg, after assignment or transfer)
inline SortableList();
inline constexpr SortableList() noexcept;
//- Construct given size, sort later.
// The indices remain empty until the list is sorted

View File

@ -68,6 +68,15 @@ class UIndirectList
UList<T>& values_;
const labelUList& addressing_;
protected:
// Protected Member Functions
//- True if there are two or more entries and all entries have
// identical values.
inline bool uniform() const;
public:
// STL type definitions

View File

@ -23,6 +23,32 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class T>
inline bool Foam::UIndirectList<T>::uniform() const
{
const label len = this->size();
if (len > 1)
{
const T& val = (*this)[0];
for (label i=1; i<len; ++i)
{
if (val != (*this)[i])
{
return false;
}
}
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>

View File

@ -37,37 +37,17 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
const label shortListLen
) const
{
const UIndirectList<T>& L = *this;
const UIndirectList<T>& list = *this;
const label len = L.size();
const label len = list.size();
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (len > 1 && contiguous<T>());
if (uniform)
if (contiguous<T>() && list.uniform())
{
for (label i=1; i < len; ++i)
{
if (L[i] != L[0])
{
uniform = false;
break;
}
}
}
if (uniform)
{
// Size and start delimiter
os << len << token::BEGIN_BLOCK;
// Contents
os << L[0];
// End delimiter
os << token::END_BLOCK;
// Two or more entries, and all entries have identical values.
os << len << token::BEGIN_BLOCK << list[0] << token::END_BLOCK;
}
else if
(
@ -82,7 +62,7 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
for (label i=0; i < len; ++i)
{
if (i) os << token::SPACE;
os << L[i];
os << list[i];
}
// End delimiter
@ -96,7 +76,7 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
// Contents
for (label i=0; i < len; ++i)
{
os << L[i] << nl;
os << list[i] << nl;
}
// End delimiter
@ -119,7 +99,7 @@ Foam::Ostream& Foam::UIndirectList<T>::writeList
{
os.writeRaw
(
reinterpret_cast<const char*>(&(L[i])),
reinterpret_cast<const char*>(&(list[i])),
sizeof(T)
);
}

View File

@ -108,6 +108,10 @@ protected:
// Use with care
inline void size(const label n);
//- True if there are two or more entries and all entries have
// identical values.
inline bool uniform() const;
//- Write the UList with its compound type
void writeEntry(Ostream& os) const;
@ -433,7 +437,7 @@ public:
inline bool empty() const;
//- Swap content with another UList of the same type in constant time
inline void swap(UList<T>& lst);
inline void swap(UList<T>& list);
// STL member operators
@ -476,7 +480,7 @@ public:
friend Ostream& operator<< <T>
(
Ostream& os,
const UList<T>& lst
const UList<T>& list
);
//- Read List contents from Istream.
@ -508,11 +512,11 @@ void shuffle(UList<T>& a);
// Reverse the first n elements of the list
template<class T>
inline void reverse(UList<T>& lst, const label n);
inline void reverse(UList<T>& list, const label n);
// Reverse all the elements of the list
template<class T>
inline void reverse(UList<T>& lst);
inline void reverse(UList<T>& list);
// Exchange contents of lists - see UList::swap().
template<class T>

View File

@ -27,6 +27,33 @@ License
#include "pTraits.H"
#include "Swap.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class T>
inline bool Foam::UList<T>::uniform() const
{
const label len = size();
if (len > 1)
{
const T& val = first();
for (label i=1; i<len; ++i)
{
if (val != (*this)[i])
{
return false;
}
}
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
@ -358,29 +385,29 @@ inline bool Foam::UList<T>::empty() const
template<class T>
inline void Foam::UList<T>::swap(UList<T>& lst)
inline void Foam::UList<T>::swap(UList<T>& list)
{
Foam::Swap(size_, lst.size_);
Foam::Swap(v_, lst.v_);
Foam::Swap(size_, list.size_);
Foam::Swap(v_, list.v_);
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class T>
inline void Foam::reverse(UList<T>& lst, const label n)
inline void Foam::reverse(UList<T>& list, const label n)
{
for (label i=0; i<n/2; ++i)
{
Foam::Swap(lst[i], lst[n-1-i]);
Foam::Swap(list[i], list[n-1-i]);
}
}
template<class T>
inline void Foam::reverse(UList<T>& lst)
inline void Foam::reverse(UList<T>& list)
{
reverse(lst, lst.size());
reverse(list, list.size());
}

View File

@ -74,37 +74,17 @@ Foam::Ostream& Foam::UList<T>::writeList
const label shortListLen
) const
{
const UList<T>& L = *this;
const UList<T>& list = *this;
const label len = L.size();
const label len = list.size();
// Write list contents depending on data format
if (os.format() == IOstream::ASCII || !contiguous<T>())
{
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (len > 1 && contiguous<T>());
if (uniform)
if (contiguous<T>() && list.uniform())
{
for (label i=1; i < len; ++i)
{
if (L[i] != L[0])
{
uniform = false;
break;
}
}
}
if (uniform)
{
// Size and start delimiter
os << len << token::BEGIN_BLOCK;
// Contents
os << L[0];
// End delimiter
os << token::END_BLOCK;
// Two or more entries, and all entries have identical values.
os << len << token::BEGIN_BLOCK << list[0] << token::END_BLOCK;
}
else if
(
@ -119,7 +99,7 @@ Foam::Ostream& Foam::UList<T>::writeList
for (label i=0; i < len; ++i)
{
if (i) os << token::SPACE;
os << L[i];
os << list[i];
}
// End delimiter
@ -133,7 +113,7 @@ Foam::Ostream& Foam::UList<T>::writeList
// Contents
for (label i=0; i < len; ++i)
{
os << L[i] << nl;
os << list[i] << nl;
}
// End delimiter
@ -150,8 +130,8 @@ Foam::Ostream& Foam::UList<T>::writeList
// write(...) includes surrounding start/end delimiters
os.write
(
reinterpret_cast<const char*>(L.cdata()),
L.byteSize()
reinterpret_cast<const char*>(list.cdata()),
list.byteSize()
);
}
}
@ -164,17 +144,17 @@ Foam::Ostream& Foam::UList<T>::writeList
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class T>
Foam::Ostream& Foam::operator<<(Ostream& os, const UList<T>& lst)
Foam::Ostream& Foam::operator<<(Ostream& os, const UList<T>& list)
{
return lst.writeList(os, 10);
return list.writeList(os, 10);
}
template<class T>
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
Foam::Istream& Foam::operator>>(Istream& is, UList<T>& list)
{
// The target list length - must match with sizes read
const label len = lst.size();
const label len = list.size();
is.fatalCheck(FUNCTION_NAME);
@ -207,7 +187,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
for (label i = 0; i < len; ++i)
{
lst[i] = std::move(elems[i]);
list[i] = std::move(elems[i]);
}
return is;
@ -241,7 +221,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
{
for (label i=0; i<len; ++i)
{
is >> lst[i];
is >> list[i];
is.fatalCheck
(
@ -264,7 +244,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
for (label i=0; i<len; ++i)
{
lst[i] = element; // Copy the value
list[i] = element; // Copy the value
}
}
}
@ -276,7 +256,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
{
// Non-empty, binary, contiguous
is.read(reinterpret_cast<char*>(lst.data()), len*sizeof(T));
is.read(reinterpret_cast<char*>(list.data()), len*sizeof(T));
is.fatalCheck
(
@ -315,7 +295,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& lst)
// Move assign each list element
for (label i = 0; i < len; ++i)
{
lst[i] = std::move(sll.removeHead());
list[i] = std::move(sll.removeHead());
}
return is;

View File

@ -56,7 +56,7 @@ namespace Foam
template<class T> class PtrList;
template<class T> class UPtrList;
template<class T> Ostream& operator<<(Ostream& os, const UPtrList<T>& lst);
template<class T> Ostream& operator<<(Ostream& os, const UPtrList<T>& list);
/*---------------------------------------------------------------------------*\
@ -96,7 +96,7 @@ public:
// Constructors
//- Construct null
UPtrList() = default;
inline constexpr UPtrList() noexcept;
//- Construct with specified size, each element initialized to nullptr
explicit inline UPtrList(const label len);
@ -104,19 +104,19 @@ public:
//- Construct from PtrList, copying addresses of each list element.
// The argument is non-const access since this UPtrList can be used
// to change its values.
explicit inline UPtrList(PtrList<T>& lst);
explicit inline UPtrList(PtrList<T>& list);
//- Construct from UList, taking addresses of each list element
explicit UPtrList(UList<T>& lst);
explicit UPtrList(UList<T>& list);
//- Construct as copy or re-use as specified
inline UPtrList(UPtrList<T>& lst, bool reuse);
inline UPtrList(UPtrList<T>& list, bool reuse);
//- Copy construct
inline UPtrList(const UPtrList<T>& lst) = default;
inline UPtrList(const UPtrList<T>& list) = default;
//- Move construct
inline UPtrList(UPtrList<T>&& lst);
inline UPtrList(UPtrList<T>&& list);
// Member functions
@ -149,20 +149,20 @@ public:
//- Reset size of UPtrList.
// New entries are initialized to nullptr.
inline void setSize(const label newLen);
inline void resize(const label newLen);
//- Reset size of UPtrList.
// New entries are initialized to nullptr.
inline void resize(const label newLen);
inline void setSize(const label newLen);
//- Append an element to the end of the list
inline void append(T* ptr);
//- Swap content
inline void swap(UPtrList<T>& lst);
inline void swap(UPtrList<T>& list);
//- Transfer contents into this list and annul the argument
inline void transfer(UPtrList<T>& lst);
inline void transfer(UPtrList<T>& list);
//- Return true if element is set (ie, not a nullptr)
inline bool set(const label i) const;
@ -187,10 +187,10 @@ public:
inline const T* operator()(const label i) const;
//- Copy assignment
UPtrList<T>& operator=(const UPtrList<T>& lst) = default;
UPtrList<T>& operator=(const UPtrList<T>& list) = default;
//- Move assignment
inline void operator=(UPtrList<T>&& lst);
inline void operator=(UPtrList<T>&& list);
// Iterators
@ -319,7 +319,7 @@ public:
// IOstream operator
//- Write UPtrList to Ostream
friend Ostream& operator<< <T>(Ostream& os, const UPtrList<T>& lst);
friend Ostream& operator<< <T>(Ostream& os, const UPtrList<T>& list);
};

View File

@ -25,6 +25,13 @@ License
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
inline constexpr Foam::UPtrList<T>::UPtrList() noexcept
:
ptrs_()
{}
template<class T>
inline Foam::UPtrList<T>::UPtrList(const label len)
:
@ -33,23 +40,23 @@ inline Foam::UPtrList<T>::UPtrList(const label len)
template<class T>
inline Foam::UPtrList<T>::UPtrList(PtrList<T>& lst)
inline Foam::UPtrList<T>::UPtrList(PtrList<T>& list)
:
ptrs_(lst.ptrs_)
ptrs_(list.ptrs_)
{}
template<class T>
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>&& lst)
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>&& list)
:
ptrs_(std::move(lst.ptrs_))
ptrs_(std::move(list.ptrs_))
{}
template<class T>
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>& lst, bool reuse)
inline Foam::UPtrList<T>::UPtrList(UPtrList<T>& list, bool reuse)
:
ptrs_(lst.ptrs_, reuse)
ptrs_(list.ptrs_, reuse)
{}
@ -77,16 +84,16 @@ inline void Foam::UPtrList<T>::clear()
template<class T>
inline void Foam::UPtrList<T>::swap(UPtrList<T>& lst)
inline void Foam::UPtrList<T>::swap(UPtrList<T>& list)
{
ptrs_.swap(lst.ptrs_);
ptrs_.swap(list.ptrs_);
}
template<class T>
inline void Foam::UPtrList<T>::transfer(UPtrList<T>& lst)
inline void Foam::UPtrList<T>::transfer(UPtrList<T>& list)
{
ptrs_.transfer(lst.ptrs_);
ptrs_.transfer(list.ptrs_);
}
@ -119,7 +126,7 @@ inline const T& Foam::UPtrList<T>::last() const
template<class T>
inline void Foam::UPtrList<T>::setSize(const label newLen)
inline void Foam::UPtrList<T>::resize(const label newLen)
{
if (newLen <= 0)
{
@ -131,15 +138,15 @@ inline void Foam::UPtrList<T>::setSize(const label newLen)
if (newLen != oldLen)
{
// Truncate or extend. Any new elements are initialized to nullptr.
ptrs_.setSize(newLen, reinterpret_cast<T*>(0));
ptrs_.resize(newLen, reinterpret_cast<T*>(0));
}
}
template<class T>
inline void Foam::UPtrList<T>::resize(const label nElem)
inline void Foam::UPtrList<T>::setSize(const label newLen)
{
this->setSize(nElem);
this->resize(newLen);
}
@ -147,7 +154,7 @@ template<class T>
inline void Foam::UPtrList<T>::append(T* ptr)
{
const label idx = this->size();
ptrs_.setSize(idx + 1);
ptrs_.resize(idx + 1);
ptrs_[idx] = ptr;
}
@ -590,10 +597,9 @@ Foam::UPtrList<T>::end() const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline void Foam::UPtrList<T>::operator=(UPtrList<T>&& lst)
inline void Foam::UPtrList<T>::operator=(UPtrList<T>&& list)
{
this->clear();
this->swap(lst);
this->transfer(list);
}

View File

@ -105,7 +105,7 @@ void checkFields
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<template<class> class Field, class Type>
FieldField<Field, Type>::FieldField()
constexpr FieldField<Field, Type>::FieldField() noexcept
:
PtrList<Field<Type>>()
{}

View File

@ -46,7 +46,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
template<template<class> class Field, class Type>
class FieldField;
@ -87,7 +87,7 @@ public:
//- Construct null
// Used for temporary fields which are initialised after construction
FieldField();
constexpr FieldField() noexcept;
//- Construct given size
// Used for temporary fields which are initialised after construction

View File

@ -100,7 +100,7 @@ public:
// Constructors
//- Construct null
inline DynamicField();
inline constexpr DynamicField() noexcept;
//- Construct with given capacity.
explicit inline DynamicField(const label len);

View File

@ -54,10 +54,10 @@ inline void Foam::DynamicField<T, SizeMin>::assignDynField
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::DynamicField<T, SizeMin>::DynamicField()
inline constexpr Foam::DynamicField<T, SizeMin>::DynamicField() noexcept
:
Field<T>(),
capacity_(Field<T>::size())
capacity_(0)
{}

View File

@ -37,83 +37,6 @@ const char* const Foam::Field<Type>::typeName("Field");
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Field<Type>::Field()
:
List<Type>()
{}
template<class Type>
Foam::Field<Type>::Field(const label len)
:
List<Type>(len)
{}
template<class Type>
Foam::Field<Type>::Field(const label len, const Type& val)
:
List<Type>(len, val)
{}
template<class Type>
Foam::Field<Type>::Field(const label len, const zero)
:
List<Type>(len, Zero)
{}
template<class Type>
Foam::Field<Type>::Field(const Field<Type>& fld)
:
List<Type>(fld)
{}
template<class Type>
Foam::Field<Type>::Field(const UList<Type>& list)
:
List<Type>(list)
{}
template<class Type>
Foam::Field<Type>::Field(const UIndirectList<Type>& list)
:
List<Type>(list)
{}
template<class Type>
Foam::Field<Type>::Field(Field<Type>&& fld)
:
List<Type>()
{
List<Type>::transfer(fld);
}
template<class Type>
Foam::Field<Type>::Field(List<Type>&& list)
:
List<Type>()
{
List<Type>::transfer(list);
}
template<class Type>
template<int SizeMin>
Foam::Field<Type>::Field(DynamicList<Type, SizeMin>&& list)
:
List<Type>()
{
List<Type>::transfer(list);
}
template<class Type>
Foam::Field<Type>::Field
(
@ -256,31 +179,6 @@ Foam::Field<Type>::Field
}
template<class Type>
Foam::Field<Type>::Field(Field<Type>& fld, bool reuse)
:
List<Type>(fld, reuse)
{}
#ifndef NoConstructFromTmp
template<class Type>
Foam::Field<Type>::Field(const tmp<Field<Type>>& tfld)
:
List<Type>(tfld.constCast(), tfld.movable())
{
tfld.clear();
}
#endif
template<class Type>
Foam::Field<Type>::Field(Istream& is)
:
List<Type>(is)
{}
template<class Type>
Foam::Field<Type>::Field
(
@ -356,13 +254,6 @@ Foam::Field<Type>::Field
}
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Field<Type>::clone() const
{
return tmp<Field<Type>>::New(*this);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
@ -739,13 +630,17 @@ void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const
{
os.writeKeyword(keyword);
const label len = this->size();
// Can the contents be considered 'uniform' (ie, identical)?
bool uniform = (this->size() && contiguous<Type>());
bool uniform = (contiguous<Type>() && len);
if (uniform)
{
forAll(*this, i)
const Type& val = this->operator[](0);
for (label i=1; i<len; ++i)
{
if (this->operator[](i) != this->operator[](0))
if (val != this->operator[](i))
{
uniform = false;
break;
@ -783,20 +678,6 @@ void Foam::Field<Type>::operator=(const Field<Type>& rhs)
}
template<class Type>
void Foam::Field<Type>::operator=(const UList<Type>& rhs)
{
List<Type>::operator=(rhs);
}
template<class Type>
void Foam::Field<Type>::operator=(const SubField<Type>& rhs)
{
List<Type>::operator=(rhs);
}
template<class Type>
void Foam::Field<Type>::operator=(const tmp<Field>& rhs)
{
@ -811,42 +692,6 @@ void Foam::Field<Type>::operator=(const tmp<Field>& rhs)
}
template<class Type>
void Foam::Field<Type>::operator=(Field<Type>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
void Foam::Field<Type>::operator=(List<Type>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
template<int SizeMin>
void Foam::Field<Type>::operator=(DynamicList<Type, SizeMin>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
void Foam::Field<Type>::operator=(const Type& val)
{
List<Type>::operator=(val);
}
template<class Type>
void Foam::Field<Type>::operator=(const zero)
{
List<Type>::operator=(Zero);
}
template<class Type>
template<class Form, class Cmpt, Foam::direction nCmpt>
void Foam::Field<Type>::operator=(const VectorSpace<Form,Cmpt,nCmpt>& vs)

View File

@ -31,6 +31,7 @@ SourceFiles
FieldFunctions.H
FieldFunctionsM.H
FieldMapper.H
FieldI.H
FieldM.H
Field.C
FieldFunctions.C
@ -103,36 +104,36 @@ public:
//- Construct null
// For temporary fields that are initialised after construction
Field();
inline constexpr Field() noexcept;
//- Construct given size
// For temporary fields that are initialised after construction
explicit Field(const label len);
inline explicit Field(const label len);
//- Construct given size and initial value
Field(const label len, const Type& val);
inline Field(const label len, const Type& val);
//- Construct given size and initial values of zero
Field(const label len, const zero);
inline Field(const label len, const zero);
//- Copy construct
Field(const Field<Type>& fld);
inline Field(const Field<Type>& fld);
//- Copy construct from UList\<Type\>
explicit Field(const UList<Type>& list);
inline explicit Field(const UList<Type>& list);
//- Copy construct from UIndirectList\<Type\>
explicit Field(const UIndirectList<Type>& list);
inline explicit Field(const UIndirectList<Type>& list);
//- Move construct from Field
Field(Field<Type>&& fld);
inline Field(Field<Type>&& fld);
//- Move construct from List
Field(List<Type>&& list);
inline Field(List<Type>&& list);
//- Move construct from DynamicList
template<int SizeMin>
Field(DynamicList<Type, SizeMin>&& list);
inline Field(DynamicList<Type, SizeMin>&& list);
//- Construct by 1 to 1 mapping from the given field
Field
@ -219,21 +220,21 @@ public:
);
//- Copy construct or re-use as specified.
Field(Field<Type>& fld, bool reuse);
inline Field(Field<Type>& fld, bool reuse);
//- Copy or move construct from tmp
#ifndef NoConstructFromTmp
Field(const tmp<Field<Type>>& tfld);
inline Field(const tmp<Field<Type>>& tfld);
#endif
//- Construct from Istream
Field(Istream& is);
inline Field(Istream& is);
//- Construct from a dictionary entry
Field(const word& keyword, const dictionary& dict, const label len);
//- Clone
tmp<Field<Type>> clone() const;
inline tmp<Field<Type>> clone() const;
//- Return a pointer to a new calculatedFvPatchFieldField created on
// freestore without setting patchField values
@ -358,21 +359,21 @@ public:
//- Copy assignment
void operator=(const Field<Type>&);
void operator=(const UList<Type>&);
void operator=(const SubField<Type>&);
void operator=(const tmp<Field<Type>>&);
inline void operator=(const UList<Type>&);
inline void operator=(const SubField<Type>&);
//- Move assignment
void operator=(Field<Type>&& rhs);
void operator=(List<Type>&& rhs);
inline void operator=(Field<Type>&& rhs);
inline void operator=(List<Type>&& rhs);
template<int SizeMin>
void operator=(DynamicList<Type, SizeMin>&& rhs);
inline void operator=(DynamicList<Type, SizeMin>&& rhs);
//- Value assignment
void operator=(const Type&);
void operator=(const zero);
inline void operator=(const Type& val);
inline void operator=(const zero);
template<class Form, class Cmpt, direction nCmpt>
void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
@ -412,6 +413,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "FieldI.H"
#include "FieldFunctions.H"
#ifdef NoRepository

View File

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
inline constexpr Foam::Field<Type>::Field() noexcept
:
List<Type>()
{}
template<class Type>
inline Foam::Field<Type>::Field(const label len)
:
List<Type>(len)
{}
template<class Type>
inline Foam::Field<Type>::Field(const label len, const Type& val)
:
List<Type>(len, val)
{}
template<class Type>
inline Foam::Field<Type>::Field(const label len, const zero)
:
List<Type>(len, Zero)
{}
template<class Type>
inline Foam::Field<Type>::Field(const Field<Type>& fld)
:
List<Type>(fld)
{}
template<class Type>
inline Foam::Field<Type>::Field(const UList<Type>& list)
:
List<Type>(list)
{}
template<class Type>
inline Foam::Field<Type>::Field(const UIndirectList<Type>& list)
:
List<Type>(list)
{}
template<class Type>
inline Foam::Field<Type>::Field(Field<Type>&& fld)
:
List<Type>()
{
List<Type>::transfer(fld);
}
template<class Type>
inline Foam::Field<Type>::Field(List<Type>&& list)
:
List<Type>()
{
List<Type>::transfer(list);
}
template<class Type>
template<int SizeMin>
inline Foam::Field<Type>::Field(DynamicList<Type, SizeMin>&& list)
:
List<Type>()
{
List<Type>::transfer(list);
}
template<class Type>
inline Foam::Field<Type>::Field(Field<Type>& fld, bool reuse)
:
List<Type>(fld, reuse)
{}
#ifndef NoConstructFromTmp
template<class Type>
inline Foam::Field<Type>::Field(const tmp<Field<Type>>& tfld)
:
List<Type>(tfld.constCast(), tfld.movable())
{
tfld.clear();
}
#endif
template<class Type>
inline Foam::Field<Type>::Field(Istream& is)
:
List<Type>(is)
{}
template<class Type>
inline Foam::tmp<Foam::Field<Type>> Foam::Field<Type>::clone() const
{
return tmp<Field<Type>>::New(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
inline void Foam::Field<Type>::operator=(const UList<Type>& rhs)
{
List<Type>::operator=(rhs);
}
template<class Type>
inline void Foam::Field<Type>::operator=(const SubField<Type>& rhs)
{
List<Type>::operator=(rhs);
}
template<class Type>
inline void Foam::Field<Type>::operator=(Field<Type>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
inline void Foam::Field<Type>::operator=(List<Type>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
template<int SizeMin>
inline void Foam::Field<Type>::operator=(DynamicList<Type, SizeMin>&& rhs)
{
List<Type>::transfer(rhs);
}
template<class Type>
inline void Foam::Field<Type>::operator=(const Type& val)
{
List<Type>::operator=(val);
}
template<class Type>
inline void Foam::Field<Type>::operator=(const zero)
{
List<Type>::operator=(Zero);
}
// ************************************************************************* //

View File

@ -60,7 +60,7 @@ public:
// Constructors
//- Construct null initializing count to 0
refCount()
constexpr refCount() noexcept
:
count_(0)
{}
@ -69,13 +69,13 @@ public:
// Member Functions
//- Return the current reference count
int count() const
int count() const noexcept
{
return count_;
}
//- Return true if the reference count is zero
bool unique() const
bool unique() const noexcept
{
return !count_;
}