Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: third_party/base/stl_util.h

Issue 2484953003: Force compiler to deduce src type for checked_cast<dst, src>. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ 5 #ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ 6 #define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 23 matching lines...) Expand all
34 class FakeUniquePtr : public std::unique_ptr<T> { 34 class FakeUniquePtr : public std::unique_ptr<T> {
35 public: 35 public:
36 using std::unique_ptr<T>::unique_ptr; 36 using std::unique_ptr<T>::unique_ptr;
37 ~FakeUniquePtr() { std::unique_ptr<T>::release(); } 37 ~FakeUniquePtr() { std::unique_ptr<T>::release(); }
38 }; 38 };
39 39
40 // Convenience routine for "int-fected" code, so that the stl collection 40 // Convenience routine for "int-fected" code, so that the stl collection
41 // size_t size() method return values will be checked. 41 // size_t size() method return values will be checked.
42 template <typename ResultType, typename Collection> 42 template <typename ResultType, typename Collection>
43 ResultType CollectionSize(const Collection& collection) { 43 ResultType CollectionSize(const Collection& collection) {
44 return pdfium::base::checked_cast<ResultType, size_t>(collection.size()); 44 return pdfium::base::checked_cast<ResultType>(collection.size());
45 } 45 }
46 46
47 // Track the addition of an object to a set, removing it automatically when 47 // Track the addition of an object to a set, removing it automatically when
48 // the ScopedSetInsertion goes out of scope. 48 // the ScopedSetInsertion goes out of scope.
49 template <typename T> 49 template <typename T>
50 class ScopedSetInsertion { 50 class ScopedSetInsertion {
51 public: 51 public:
52 ScopedSetInsertion(std::set<T>* org_set, T elem) 52 ScopedSetInsertion(std::set<T>* org_set, T elem)
53 : m_Set(org_set), m_Entry(elem) { 53 : m_Set(org_set), m_Entry(elem) {
54 m_Set->insert(m_Entry); 54 m_Set->insert(m_Entry);
55 } 55 }
56 ~ScopedSetInsertion() { m_Set->erase(m_Entry); } 56 ~ScopedSetInsertion() { m_Set->erase(m_Entry); }
57 57
58 private: 58 private:
59 std::set<T>* const m_Set; 59 std::set<T>* const m_Set;
60 const T m_Entry; 60 const T m_Entry;
61 }; 61 };
62 62
63 } // namespace pdfium 63 } // namespace pdfium
64 64
65 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_ 65 #endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698