Flutter Engine
 
Loading...
Searching...
No Matches
dl_comparable.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_DISPLAY_LIST_UTILS_DL_COMPARABLE_H_
6#define FLUTTER_DISPLAY_LIST_UTILS_DL_COMPARABLE_H_
7
8#include <memory>
9
10namespace flutter {
11
12// These templates implement deep pointer comparisons that compare not
13// just the pointers to the objects, but also their contents (provided
14// that the <T> class implements the == operator override).
15// Any combination of shared_ptr<T> or T* are supported and null pointers
16// are not equal to anything but another null pointer.
17
18template <class T, class U>
19bool Equals(const T* a, const U* b) {
20 if (a == b) {
21 return true;
22 }
23 if (!a || !b) {
24 return false;
25 }
26 return *a == *b;
27}
28
29template <class T, class U>
30bool Equals(const std::shared_ptr<const T>& a, const U* b) {
31 return Equals(a.get(), b);
32}
33
34template <class T, class U>
35bool Equals(const std::shared_ptr<T>& a, const U* b) {
36 return Equals(a.get(), b);
37}
38
39template <class T, class U>
40bool Equals(const T* a, const std::shared_ptr<const U>& b) {
41 return Equals(a, b.get());
42}
43
44template <class T, class U>
45bool Equals(const T* a, const std::shared_ptr<U>& b) {
46 return Equals(a, b.get());
47}
48
49template <class T, class U>
50bool Equals(const std::shared_ptr<const T>& a,
51 const std::shared_ptr<const U>& b) {
52 return Equals(a.get(), b.get());
53}
54
55template <class T, class U>
56bool Equals(const std::shared_ptr<T>& a, const std::shared_ptr<const U>& b) {
57 return Equals(a.get(), b.get());
58}
59
60template <class T, class U>
61bool Equals(const std::shared_ptr<const T>& a, const std::shared_ptr<U>& b) {
62 return Equals(a.get(), b.get());
63}
64
65template <class T, class U>
66bool Equals(const std::shared_ptr<T>& a, const std::shared_ptr<U>& b) {
67 return Equals(a.get(), b.get());
68}
69
70template <class T, class U>
71bool NotEquals(const T* a, const U* b) {
72 return !Equals(a, b);
73}
74
75template <class T, class U>
76bool NotEquals(const std::shared_ptr<const T>& a, const U* b) {
77 return !Equals(a.get(), b);
78}
79
80template <class T, class U>
81bool NotEquals(const std::shared_ptr<T>& a, const U* b) {
82 return !Equals(a.get(), b);
83}
84
85template <class T, class U>
86bool NotEquals(const T* a, const std::shared_ptr<const U>& b) {
87 return !Equals(a, b.get());
88}
89
90template <class T, class U>
91bool NotEquals(const T* a, const std::shared_ptr<U>& b) {
92 return !Equals(a, b.get());
93}
94
95template <class T, class U>
96bool NotEquals(const std::shared_ptr<const T>& a,
97 const std::shared_ptr<const U>& b) {
98 return !Equals(a.get(), b.get());
99}
100
101template <class T, class U>
102bool NotEquals(const std::shared_ptr<T>& a, const std::shared_ptr<const U>& b) {
103 return !Equals(a.get(), b.get());
104}
105
106template <class T, class U>
107bool NotEquals(const std::shared_ptr<const T>& a, const std::shared_ptr<U>& b) {
108 return !Equals(a.get(), b.get());
109}
110
111template <class T, class U>
112bool NotEquals(const std::shared_ptr<T>& a, const std::shared_ptr<U>& b) {
113 return !Equals(a.get(), b.get());
114}
115
116} // namespace flutter
117
118#endif // FLUTTER_DISPLAY_LIST_UTILS_DL_COMPARABLE_H_
bool Equals(const T *a, const U *b)
bool NotEquals(const T *a, const U *b)