Skip to content

Commit 0a4e726

Browse files
committed
util: add deep comparison helpers for shared_ptr
1 parent c4f1175 commit 0a4e726

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ BITCOIN_CORE_H = \
365365
util/moneystr.h \
366366
util/overflow.h \
367367
util/overloaded.h \
368+
util/pointer.h \
368369
util/ranges.h \
369370
util/readwritefile.h \
370371
util/underlying.h \

src/evo/deterministicmns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CDeterministicMNList
180180
}
181181
}
182182

183-
template<typename Stream>
183+
template <typename Stream>
184184
void Unserialize(Stream& s)
185185
{
186186
Clear();

src/util/pointer.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025 The Dash Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_UTIL_POINTER_H
6+
#define BITCOIN_UTIL_POINTER_H
7+
8+
#include <memory>
9+
10+
namespace util {
11+
/* Deep equality comparison helper for std::shared_ptr<T> */
12+
template <typename T>
13+
bool shared_ptr_equal(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs)
14+
requires requires { *lhs == *rhs; }
15+
{
16+
/* Same object or both blank */
17+
if (lhs == rhs) return true;
18+
/* Inequal initialization state */
19+
if (!lhs || !rhs) return false;
20+
/* Deep comparison */
21+
return *lhs == *rhs;
22+
}
23+
24+
/* Deep inequality comparison helper for std::shared_ptr<T> */
25+
template <typename T>
26+
bool shared_ptr_not_equal(const std::shared_ptr<T>& lhs, const std::shared_ptr<T>& rhs)
27+
requires requires { *lhs != *rhs; }
28+
{
29+
/* Same object or both blank */
30+
if (lhs == rhs) return false;
31+
/* Inequal initialization state */
32+
if (!lhs || !rhs) return true;
33+
/* Deep comparison */
34+
return *lhs != *rhs;
35+
}
36+
} // namespace util
37+
38+
#endif // BITCOIN_UTIL_POINTER_H

test/util/data/non-backported.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ src/unordered_lru_cache.h
4242
src/util/edge.*
4343
src/util/enumerate.h
4444
src/util/irange.h
45+
src/util/pointer.h
4546
src/util/ranges.h
4647
src/util/ranges_set.*
4748
src/util/wpipe.*

0 commit comments

Comments
 (0)