ScummVM API documentation
algorithms.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef HPL1_ALGORITHMS
23 #define HPL1_ALGORITHMS
24 
25 #include "common/array.h"
26 
27 namespace Hpl1 {
28 
29 template<typename T, typename V>
30 void resizeAndFill(Common::Array<T> &container, const typename Common::Array<T>::size_type newSize, const V &value) {
31  const auto oldSize = container.size();
32  container.resize(newSize);
33  for (auto i = oldSize; i < newSize; ++i)
34  container[i] = value;
35 }
36 
37 template<typename RandomIt, typename Pred>
38 RandomIt removeIf(RandomIt begin, RandomIt end, Pred pred) {
39  for (auto i = begin; i != end; ++i) {
40  if (!pred(*i))
41  *begin++ = *i;
42  }
43  return begin;
44 }
45 
46 } // namespace Hpl1
47 
48 #endif // HPL1_ALGORITHMS
Definition: array.h:52
size_type size() const
Definition: array.h:315
void resize(size_type newSize)
Definition: array.h:411
uint size_type
Definition: array.h:59
Definition: algorithms.h:27