Commit 3a1a3534 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

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;
parent 765493b6
......@@ -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)
{
......
......@@ -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;
......
Markdown is supported
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