refactor: Use C++20 std::identity over IntIdentity
What changed, and why it matters
This commit is a straightforward code cleanup: it replaces a small custom helper named IntIdentity with the standard C++20 std::identity from the <functional> header. The behavior of the ConvertBits function is unchanged; only the implementation is simplified. There is no security-relevant change.
No action needed; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff removes an anonymous-namespace helper struct IntIdentity and changes the default template argument for ConvertBits’s infn parameter from IntIdentity to std::identity. std::identity is a standard C++20 type that returns its argument unchanged, matching the previous custom implementation exactly. The function signature and semantics remain the same.
Changed components
src/util/strencodings.hInspect captured patch +4 / −11
diff --git a/src/util/strencodings.h b/src/util/strencodings.h
index 30770e6d..d9bc4d5a 100644
--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -17,6 +17,7 @@
#include <charconv>
#include <cstddef>
#include <cstdint>
+#include <functional>
#include <limits>
#include <optional>
#include <span>
@@ -214,18 +215,10 @@ bool TimingResistantEqual(const T& a, const T& b)
*/
[[nodiscard]] bool ParseFixedPoint(std::string_view, int decimals, int64_t *amount_out);
-namespace {
-/** Helper class for the default infn argument to ConvertBits (just returns the input). */
-struct IntIdentity
-{
- [[maybe_unused]] int operator()(int x) const { return x; }
-};
-
-} // namespace
-
/** Convert from one power-of-2 number base to another. */
-template<int frombits, int tobits, bool pad, typename O, typename It, typename I = IntIdentity>
-bool ConvertBits(O outfn, It it, It end, I infn = {}) {
+template <int frombits, int tobits, bool pad, typename O, typename It, typename I = std::identity>
+bool ConvertBits(O outfn, It it, It end, I infn = {})
+{
size_t acc = 0;
size_t bits = 0;
constexpr size_t maxv = (1 << tobits) - 1;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.