diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2024-03-25 18:44:23 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2024-04-25 16:08:24 -0400 |
commit | 6a8b2befeab25e4e92d8e947a23e78014695e06c (patch) | |
tree | 96ec945314aa23726bcac64ea035f6e16962a750 /src/util/result.h | |
parent | 834f65e82405bbed336f98996bc8cef366bbed0f (diff) |
refactor: Avoid copying util::Result values
Copying util::Result values is less efficient than moving them because they
allocate memory and contain strings. Also this is needed to avoid compile
errors in https://github.com/bitcoin/bitcoin/pull/25722 which adds a
std::unique_ptr member to util::Result which implicity disables copying.
Diffstat (limited to 'src/util/result.h')
-rw-r--r-- | src/util/result.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/util/result.h b/src/util/result.h index 11fe89af25..122a7638fa 100644 --- a/src/util/result.h +++ b/src/util/result.h @@ -39,6 +39,9 @@ private: std::variant<bilingual_str, T> m_variant; + //! Disallow copy constructor, require Result to be moved for efficiency. + Result(const Result&) = delete; + //! Disallow operator= to avoid confusion in the future when the Result //! class gains support for richer error reporting, and callers should have //! ability to set a new result value without clearing existing error @@ -53,7 +56,6 @@ public: Result() : m_variant{std::in_place_index_t<1>{}, std::monostate{}} {} // constructor for void Result(T obj) : m_variant{std::in_place_index_t<1>{}, std::move(obj)} {} Result(Error error) : m_variant{std::in_place_index_t<0>{}, std::move(error.message)} {} - Result(const Result&) = default; Result(Result&&) = default; ~Result() = default; |