/src/libphonenumber/cpp/src/phonenumbers/stl_util.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
18 | | namespace i18n { |
19 | | namespace phonenumbers { |
20 | | |
21 | | namespace gtl { |
22 | | // Compares the first attribute of two pairs. |
23 | | struct OrderByFirst { |
24 | | template <typename T> |
25 | 5.19M | bool operator()(const T& p1, const T& p2) const { |
26 | 5.19M | return p1.first < p2.first; |
27 | 5.19M | } |
28 | | }; |
29 | | |
30 | | // Deletes the second attribute (pointer type expected) of the pairs contained |
31 | | // in the provided range. |
32 | | template <typename ForwardIterator> |
33 | | void STLDeleteContainerPairSecondPointers(const ForwardIterator& begin, |
34 | 0 | const ForwardIterator& end) { |
35 | 0 | for (ForwardIterator it = begin; it != end; ++it) { |
36 | 0 | delete it->second; |
37 | 0 | } |
38 | 0 | } |
39 | | |
40 | | // Deletes the pointers contained in the provided container. |
41 | | template <typename T> |
42 | | void STLDeleteElements(T* container) { |
43 | | for (typename T::iterator it = container->begin(); it != container->end(); |
44 | | ++it) { |
45 | | delete *it; |
46 | | } |
47 | | } |
48 | | } // namespace gtl |
49 | | } // namespace phonenumbers |
50 | | } // namespace i18n |
51 | | |
52 | | #endif // I18N_PHONENUMBERS_STL_UTIL_H_ |