1// Copyright (C) 2011 The Libphonenumber Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef I18N_PHONENUMBERS_STL_UTIL_H_
16#define I18N_PHONENUMBERS_STL_UTIL_H_
17
18namespace i18n {
19namespace phonenumbers {
20
21// Compares the first attribute of two pairs.
22struct OrderByFirst {
23  template <typename T>
24  bool operator()(const T& p1, const T& p2) const {
25    return p1.first < p2.first;
26  }
27};
28
29// Deletes the second attribute (pointer type expected) of the pairs contained
30// in the provided range.
31template <typename ForwardIterator>
32void STLDeleteContainerPairSecondPointers(const ForwardIterator& begin,
33                                          const ForwardIterator& end) {
34  for (ForwardIterator it = begin; it != end; ++it) {
35    delete it->second;
36  }
37}
38
39// Deletes the pointers contained in the provided container.
40template <typename T>
41void STLDeleteElements(T* container) {
42  for (typename T::iterator it = container->begin(); it != container->end();
43       ++it) {
44    delete *it;
45  }
46}
47
48}  // namespace phonenumbers
49}  // namespace i18n
50
51#endif  // I18N_PHONENUMBERS_STL_UTIL_H_
52