STYLE: remove UList operator[] taking std::initializer_list

- unnecessary. Can deduce labelRange from the pair of labels.
  These are all the same:

      list[labelRange(18,3)] = 100;
      list[labelRange{18,3}] = 100;
      list[{18,3}] = 100;

  Removing the run-time handling of std::initializer_list in favour of
  compile-time deduction allows the future use of sliceRange as well.
  Eg,

     list[sliceRange{18,3,2}] = 100;
     list[{18,3,2}] = 100;
This commit is contained in:
Mark Olesen 2019-04-24 18:26:57 +02:00 committed by Andrew Heather
parent 765493b69f
commit 3a1a353483
2 changed files with 1 additions and 68 deletions

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 |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
@ -48,29 +48,6 @@ Foam::labelRange Foam::UList<T>::validateRange(const labelRange& range) const
}
template<class T>
Foam::labelRange Foam::UList<T>::validateRange
(
std::initializer_list<label> start_size
) const
{
if (start_size.size() != 2)
{
FatalErrorInFunction
<< "range specified with " << start_size.size()
<< " elements instead of 2"
<< abort(FatalError);
}
auto iter = start_size.begin();
const label beg = *(iter++);
const label len = *iter;
return this->validateRange(labelRange(beg, len));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
@ -176,31 +153,6 @@ const Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range) const
}
template<class T>
Foam::UList<T> Foam::UList<T>::operator[]
(
std::initializer_list<label> start_size
)
{
const labelRange slice = validateRange(start_size);
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
}
template<class T>
const Foam::UList<T> Foam::UList<T>::operator[]
(
std::initializer_list<label> start_size
) const
{
// Restricted range
const labelRange slice = validateRange(start_size);
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
}
template<class T>
void Foam::UList<T>::operator=(const T& val)
{

View File

@ -123,12 +123,6 @@ protected:
//- always addresses a valid section of the list.
labelRange validateRange(const labelRange& range) const;
//- Return a validated (start,size) subset range, which means that it
//- always addresses a valid section of the list.
labelRange validateRange
(
std::initializer_list<label> start_size_pair
) const;
public:
@ -361,19 +355,6 @@ public:
// result always addresses a valid section of the list.
const UList<T> operator[](const labelRange& range) const;
//- Return (start,size) subset from UList with non-const access.
// The range is subsetted with the list size itself to ensure that the
// result always addresses a valid section of the list.
UList<T> operator[](std::initializer_list<label> start_size);
//- Return (start,size) subset from UList with const access.
// The range is subsetted with the list size itself to ensure that the
// result always addresses a valid section of the list.
const UList<T> operator[]
(
std::initializer_list<label> start_size
) const;
//- Allow cast to a const List<T>&
inline operator const Foam::List<T>&() const;