STYLE: mark containers empty() and size() as noexcept

This commit is contained in:
Mark Olesen
2019-10-02 09:04:20 +02:00
committed by Andrew Heather
parent 2c11d875ad
commit de11575e1e
42 changed files with 124 additions and 159 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2011, 2017-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011, 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
@ -125,14 +125,15 @@ public:
// Access
//- Return true if a precompiled expression does not exist
inline bool empty() const;
inline bool empty() const noexcept;
//- Return true if a precompiled expression exists
inline bool exists() const;
inline bool exists() const noexcept;
//- The number of capture groups for a non-empty expression
inline unsigned ngroups() const;
// Editing
//- Clear expression.
@ -150,6 +151,7 @@ public:
// \return True if the pattern was compiled
bool set(const std::string& pattern, bool ignoreCase=false);
// Matching/Searching
//- Find position within the text.

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -98,15 +98,15 @@ inline Foam::regExpPosix::~regExpPosix()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline bool Foam::regExpPosix::empty() const
inline bool Foam::regExpPosix::empty() const noexcept
{
return !preg_;
}
inline bool Foam::regExpPosix::exists() const
inline bool Foam::regExpPosix::exists() const noexcept
{
return preg_ ? true : false;
return preg_;
}

View File

@ -283,7 +283,7 @@ public:
//- Number of entries.
inline label size() const noexcept;
//- Return true if the list is empty (ie, size() is zero).
//- True if the list is empty (ie, size() is zero).
inline bool empty() const noexcept;
//- The number of elements that can be stored with reallocating

View File

@ -233,13 +233,13 @@ public:
// Access
//- The size of the underlying table
inline label capacity() const;
inline label capacity() const noexcept;
//- Return number of elements in table
inline label size() const;
//- The number of elements in table
inline label size() const noexcept;
//- Return true if the hash table is empty
inline bool empty() const;
//- True if the hash table is empty
inline bool empty() const noexcept;
//- Find and return a hashed entry. FatalError if it does not exist.
inline T& at(const Key& key);

View File

@ -62,8 +62,7 @@ struct HashTableCore
static label canonicalSize(const label requested_size);
//- Construct null
HashTableCore()
{}
HashTableCore() = default;
//- Define template name and debug
ClassName("HashTable");
@ -105,8 +104,8 @@ struct HashTableCore
inline const_iterator_pair(const TableType& tbl);
inline label size() const;
inline bool empty() const;
label size() const noexcept { return size_; }
bool empty() const noexcept { return !size_; }
inline IteratorType begin() const;
inline IteratorType cbegin() const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -73,22 +73,6 @@ inline Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>
{}
template<class IteratorType, class TableType>
inline Foam::label
Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>::size() const
{
return size_;
}
template<class IteratorType, class TableType>
inline bool
Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>::empty() const
{
return !size_;
}
template<class IteratorType, class TableType>
inline IteratorType Foam::HashTableCore::const_iterator_pair
<

View File

@ -41,21 +41,21 @@ Foam::HashTable<T, Key, Hash>::hashKeyIndex(const Key& key) const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::capacity() const
inline Foam::label Foam::HashTable<T, Key, Hash>::capacity() const noexcept
{
return capacity_;
}
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
inline Foam::label Foam::HashTable<T, Key, Hash>::size() const noexcept
{
return size_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::empty() const
inline bool Foam::HashTable<T, Key, Hash>::empty() const noexcept
{
return !size_;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -83,11 +83,11 @@ public:
// Access
//- Return the number of elements in the list
inline label size() const;
//- The number of elements in the list
inline label size() const noexcept;
//- Return true if the list is empty (ie, size() is zero).
inline bool empty() const;
//- True if the list is empty (ie, size() is zero).
inline bool empty() const noexcept;
inline const UList<T>& posList() const;
inline const UList<T>& negList() const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -74,14 +74,14 @@ inline Foam::BiIndirectList<T>::BiIndirectList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::BiIndirectList<T>::size() const
inline Foam::label Foam::BiIndirectList<T>::size() const noexcept
{
return addressing_.size();
}
template<class T>
inline bool Foam::BiIndirectList<T>::empty() const
inline bool Foam::BiIndirectList<T>::empty() const noexcept
{
return addressing_.empty();
}

View File

@ -153,11 +153,11 @@ public:
// Member Functions
//- Return number of elements in list
inline label size() const;
//- The number of elements in list
inline label size() const noexcept;
//- Return true if the list is empty
inline bool empty() const;
//- True if the list is empty
inline bool empty() const noexcept;
//- Return first entry
inline link* first();

View File

@ -110,13 +110,13 @@ inline void Foam::DLListBase::link::deregister()
}
inline Foam::label Foam::DLListBase::size() const
inline Foam::label Foam::DLListBase::size() const noexcept
{
return size_;
}
inline bool Foam::DLListBase::empty() const
inline bool Foam::DLListBase::empty() const noexcept
{
return !size_;
}

View File

@ -141,11 +141,11 @@ public:
// Member Functions
//- Return number of elements in list
inline label size() const;
//- The number of elements in list
inline label size() const noexcept;
//- Return true if the list is empty
inline bool empty() const;
//- True if the list is empty
inline bool empty() const noexcept;
//- Return first entry
inline link* first();

View File

@ -69,13 +69,13 @@ inline IteratorType Foam::SLListBase::iterator_last() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::SLListBase::size() const
inline Foam::label Foam::SLListBase::size() const noexcept
{
return size_;
}
inline bool Foam::SLListBase::empty() const
inline bool Foam::SLListBase::empty() const noexcept
{
return !size_;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -141,11 +141,11 @@ public:
// Access
//- Return the primary size, i.e. the number of rows
inline label size() const;
//- The primary size (the number of rows)
inline label size() const noexcept;
//- Return true if the number of rows is zero
inline bool empty() const;
//- True if the number of rows is zero
inline bool empty() const noexcept;
//- Return the offset table (= size()+1)
inline const List<label>& offsets() const;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -118,14 +118,14 @@ Foam::CompactListList<T, Container>::null()
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const
inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept
{
return size_;
}
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const
inline bool Foam::CompactListList<T, Container>::empty() const noexcept
{
return !size_;
}

View File

@ -82,12 +82,11 @@ class DynamicList
{
static_assert(SizeMin > 0, "Invalid min size parameter");
// Private data
// Private Data
//- The capacity (allocated size) of the underlying list.
label capacity_;
private:
// Private Member Functions
@ -97,7 +96,6 @@ private:
//- Subset elements in range
label subsetElements(const labelRange& slice);
protected:
// Protected Member Functions
@ -174,13 +172,13 @@ public:
// Member Functions
// Access
// Access
//- Normal lower capacity limit - the SizeMin template parameter
inline label min_size() const;
static constexpr label min_size() noexcept { return SizeMin; }
//- Size of the underlying storage.
inline label capacity() const;
inline label capacity() const noexcept;
// Edit

View File

@ -220,14 +220,7 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::label Foam::DynamicList<T, SizeMin>::min_size() const
{
return SizeMin;
}
template<class T, int SizeMin>
inline Foam::label Foam::DynamicList<T, SizeMin>::capacity() const
inline Foam::label Foam::DynamicList<T, SizeMin>::capacity() const noexcept
{
return capacity_;
}

View File

@ -541,7 +541,7 @@ void Foam::List<T>::operator=(std::initializer_list<T> list)
List_ACCESS(T, (*this), vp);
label i = 0;
for (const auto& val : list)
for (const T& val : list)
{
vp[i] = val;
++i;

View File

@ -55,7 +55,6 @@ namespace Foam
{
// Forward declarations
class Istream;
class Ostream;
@ -112,6 +111,12 @@ class List
public:
// Related types
//- Declare type of subList
typedef SubList<T> subList;
// Static Member Functions
//- Return a null List
@ -199,12 +204,6 @@ public:
~List();
// Related types
//- Declare type of subList
typedef SubList<T> subList;
// Member Functions
// Edit

View File

@ -122,7 +122,7 @@ public:
inline void operator=(const UList<T>& list);
//- Assignment of all entries to the given value
inline void operator=(const T& t);
inline void operator=(const T& val);
};

View File

@ -125,9 +125,9 @@ inline void Foam::SubList<T>::operator=(const UList<T>& list)
template<class T>
inline void Foam::SubList<T>::operator=(const T& t)
inline void Foam::SubList<T>::operator=(const T& val)
{
UList<T>::operator=(t);
UList<T>::operator=(val);
}

View File

@ -95,26 +95,13 @@ class UList
T* __restrict__ v_;
// Private Member Functions
//- No copy assignment (shallow copy)
//
// Assignment of UList<T> may need to be either shallow (copy pointer)
// or deep (copy elements) depending on context or the particular type
// of list derived from UList and it is confusing and prone to error
// for the default assignment to be either. The solution is to
// disallow default assignment and provide separate 'shallowCopy' and
// 'deepCopy' member functions
UList<T>& operator=(const UList<T>&) = delete;
protected:
// Protected Member Functions
//- Override size to be inconsistent with allocated storage.
// Use with care
inline void size(const label n);
inline void size(const label n) noexcept;
//- Write the UList with its compound type
void writeEntry(Ostream& os) const;
@ -124,6 +111,14 @@ protected:
labelRange validateRange(const labelRange& range) const;
//- No copy assignment (default: shallow copy)
//
// Assignment may need to be shallow (copy pointer)
// or deep (copy elements) depending on context or type of list.
// Disallow default assignment and provide separate 'shallowCopy' and
// 'deepCopy' member functions.
UList<T>& operator=(const UList<T>&) = delete;
public:
// STL type definitions
@ -415,14 +410,14 @@ public:
// STL member functions
//- Return the number of elements in the UList
inline label size() const;
//- The number of elements in the UList
inline label size() const noexcept;
//- Return size of the largest possible UList
inline label max_size() const;
//- True if the UList is empty (ie, size() is zero)
inline bool empty() const noexcept;
//- Return true if the UList is empty (ie, size() is zero)
inline bool empty() const;
//- The size of the largest possible UList
static constexpr label max_size() noexcept { return labelMax; }
//- Swap content with another UList of the same type in constant time
inline void swap(UList<T>& list);
@ -468,7 +463,7 @@ public:
friend Istream& operator>> <T>
(
Istream& os,
UList<T>& L
UList<T>& list
);

View File

@ -356,28 +356,21 @@ Foam::UList<T>::crend() const
template<class T>
inline void Foam::UList<T>::size(const label n)
inline void Foam::UList<T>::size(const label n) noexcept
{
size_ = n;
}
template<class T>
inline Foam::label Foam::UList<T>::size() const
inline Foam::label Foam::UList<T>::size() const noexcept
{
return size_;
}
template<class T>
inline Foam::label Foam::UList<T>::max_size() const
{
return labelMax;
}
template<class T>
inline bool Foam::UList<T>::empty() const
inline bool Foam::UList<T>::empty() const noexcept
{
return !size_;
}

View File

@ -103,7 +103,8 @@ public:
// Access
//- Size of the underlying storage.
inline label capacity() const;
inline label capacity() const noexcept;
// Edit

View File

@ -90,7 +90,7 @@ inline Foam::PtrDynList<T, SizeMin>::PtrDynList(UList<T*>& list)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::label Foam::PtrDynList<T, SizeMin>::capacity() const
inline Foam::label Foam::PtrDynList<T, SizeMin>::capacity() const noexcept
{
return capacity_;
}

View File

@ -138,11 +138,11 @@ public:
// Access
//- Return the number of elements in the list
inline label size() const;
//- The number of elements in the list
inline label size() const noexcept;
//- Return true if the list is empty (ie, size() is zero)
inline bool empty() const;
//- True if the list is empty (ie, size() is zero)
inline bool empty() const noexcept;
//- Return reference to the first element of the list
inline T& first();

View File

@ -86,14 +86,14 @@ inline Foam::UPtrList<T>::UPtrList(UList<T>& list)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::UPtrList<T>::size() const
inline Foam::label Foam::UPtrList<T>::size() const noexcept
{
return ptrs_.size();
}
template<class T>
inline bool Foam::UPtrList<T>::empty() const
inline bool Foam::UPtrList<T>::empty() const noexcept
{
return ptrs_.empty();
}

View File

@ -172,7 +172,8 @@ public:
// Access
//- Size of the underlying storage.
inline label capacity() const;
inline label capacity() const noexcept;
// Edit

View File

@ -222,7 +222,7 @@ inline Foam::DynamicField<T, SizeMin>::DynamicField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, int SizeMin>
inline Foam::label Foam::DynamicField<T, SizeMin>::capacity() const
inline Foam::label Foam::DynamicField<T, SizeMin>::capacity() const noexcept
{
return capacity_;
}

View File

@ -349,7 +349,7 @@ public:
inline dlLibraryTable& libs();
//- The number of arguments
inline label size() const;
inline label size() const noexcept;
//- Return arguments
inline const stringList& args() const;

View File

@ -123,7 +123,7 @@ inline Foam::dlLibraryTable& Foam::argList::libs()
}
inline Foam::label Foam::argList::size() const
inline Foam::label Foam::argList::size() const noexcept
{
return args_.size();
}

View File

@ -309,7 +309,7 @@ const Foam::Time& Foam::profiling::owner() const
}
Foam::label Foam::profiling::size() const
Foam::label Foam::profiling::size() const noexcept
{
return stack_.size();
}

View File

@ -241,7 +241,7 @@ public:
const Time& owner() const;
//- The size of the current stack
label size() const;
label size() const noexcept;
//- writeData member function required by regIOobject
virtual bool writeData(Ostream& os) const;
@ -254,7 +254,6 @@ public:
IOstream::compressionType ignoreAlwaysUncompressed,
const bool valid
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -46,11 +46,10 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward declarations
class profilingInformation;
class Ostream;
// Forward declaration of friend functions and operators
Ostream& operator<<(Ostream& os, const profilingInformation& info);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -137,10 +137,10 @@ public:
// Access
//- True if the size is zero.
inline bool empty() const;
inline bool empty() const noexcept;
//- Return the number of C-strings (ie, argc)
inline int size() const;
inline int size() const noexcept;
//- Return the list of C-strings (ie, argv)
// The position at argc is a nullptr

View File

@ -111,13 +111,13 @@ inline void Foam::CStringList::clear()
}
inline bool Foam::CStringList::empty() const
inline bool Foam::CStringList::empty() const noexcept
{
return !argc_;
}
inline int Foam::CStringList::size() const
inline int Foam::CStringList::size() const noexcept
{
return argc_;
}

View File

@ -137,10 +137,10 @@ public:
// Access
//- Return true if expression is empty
inline bool empty() const;
inline bool empty() const noexcept;
//- Return true if expression is non-empty
inline bool exists() const;
inline bool exists() const noexcept;
//- The number of capture groups for a non-empty expression
inline unsigned ngroups() const;
@ -148,6 +148,7 @@ public:
// \return True if the pattern was set with ignore-case.
inline bool nocase() const;
// Editing
//- Clear expression.
@ -165,6 +166,7 @@ public:
// \return True if the pattern was compiled
bool set(const std::string& pattern, bool ignoreCase=false);
// Matching/Searching
//- Find position within the text.

View File

@ -112,13 +112,13 @@ inline Foam::regExpCxx::regExpCxx(const std::string& pattern, bool ignoreCase)
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline bool Foam::regExpCxx::empty() const
inline bool Foam::regExpCxx::empty() const noexcept
{
return !ok_;
}
inline bool Foam::regExpCxx::exists() const
inline bool Foam::regExpCxx::exists() const noexcept
{
return ok_;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -182,10 +182,10 @@ public:
// Member Functions
//- True if there are no data sets
inline bool empty() const;
inline bool empty() const noexcept;
//- The number of data sets
inline label size() const;
inline label size() const noexcept;
// Content Management

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,13 +25,13 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::vtk::seriesWriter::empty() const
inline bool Foam::vtk::seriesWriter::empty() const noexcept
{
return entries_.empty();
}
inline Foam::label Foam::vtk::seriesWriter::size() const
inline Foam::label Foam::vtk::seriesWriter::size() const noexcept
{
return entries_.size();
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -174,10 +174,10 @@ public:
inline bool decomposeRequested() const;
//- True if no cellTypes are populated.
inline bool empty() const;
inline bool empty() const noexcept;
//- The size of populated cellTypes.
inline label size() const;
inline label size() const noexcept;
// Edit

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -41,13 +41,13 @@ inline bool Foam::vtk::vtuCells::decomposeRequested() const
}
inline bool Foam::vtk::vtuCells::empty() const
inline bool Foam::vtk::vtuCells::empty() const noexcept
{
return cellTypes_.empty();
}
inline Foam::label Foam::vtk::vtuCells::size() const
inline Foam::label Foam::vtk::vtuCells::size() const noexcept
{
return cellTypes_.size();
}