aboutsummaryrefslogtreecommitdiff
path: root/src/util/result.h
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-03-25 18:44:23 -0400
committerRyan Ofsky <ryan@ofsky.org>2024-04-25 16:08:24 -0400
commit6a8b2befeab25e4e92d8e947a23e78014695e06c (patch)
tree96ec945314aa23726bcac64ea035f6e16962a750 /src/util/result.h
parent834f65e82405bbed336f98996bc8cef366bbed0f (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.h4
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;