From 1f800587f1b9fd2cbc4c26f9c5e66c03068b6d7f Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 8 Sep 2017 00:56:29 +0200 Subject: [PATCH] Removed some duplicate code in Patternies Perfect forwarding for for_each_result functor --- SilentPatch/Patterns.h | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/SilentPatch/Patterns.h b/SilentPatch/Patterns.h index 3d04d0d..c17bf5f 100644 --- a/SilentPatch/Patterns.h +++ b/SilentPatch/Patterns.h @@ -77,7 +77,7 @@ namespace hook std::vector m_matches; - bool m_matched; + bool m_matched = false; union { @@ -91,12 +91,12 @@ namespace hook protected: inline pattern(void* module) - : m_module(module), m_rangeEnd(0), m_matched(false) + : m_module(module), m_rangeEnd(0) { } inline pattern(uintptr_t begin, uintptr_t end) - : m_rangeStart(begin), m_rangeEnd(end), m_matched(false) + : m_rangeStart(begin), m_rangeEnd(end) { } @@ -120,44 +120,24 @@ namespace hook Initialize(pattern, Len-1); } - inline pattern& count(uint32_t expected) & + inline pattern&& count(uint32_t expected) { EnsureMatches(expected); assert(m_matches.size() == expected); - return *this; + return std::forward(*this); } - inline pattern& count_hint(uint32_t expected) & + inline pattern&& count_hint(uint32_t expected) { EnsureMatches(expected); - return *this; + return std::forward(*this); } - inline pattern& clear() & + inline pattern&& clear() { m_matches.clear(); m_matched = false; - return *this; - } - - inline pattern&& count(uint32_t expected) && - { - EnsureMatches(expected); - assert(m_matches.size() == expected); - return std::move(*this); - } - - inline pattern&& count_hint(uint32_t expected) && - { - EnsureMatches(expected); - return std::move(*this); - } - - inline pattern&& clear() && - { - m_matches.clear(); - m_matched = false; - return std::move(*this); + return std::forward(*this); } inline size_t size() @@ -189,12 +169,12 @@ namespace hook } template - inline void for_each_result(Pred pred) + inline void for_each_result(Pred&& pred) { EnsureMatches(UINT32_MAX); for ( auto it : m_matches ) { - pred(it); + std::forward(pred)(it); } }