From e30927285345144044c2131d89eaf4555b58832b Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Tue, 23 Jul 2024 14:39:32 +0100 Subject: [PATCH 1/2] Refactor[BMQT]: turn copy operator for Subscription explicit Signed-off-by: Evgeny Malygin --- src/groups/bmq/bmqt/bmqt_subscription.h | 39 ++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/groups/bmq/bmqt/bmqt_subscription.h b/src/groups/bmq/bmqt/bmqt_subscription.h index d1d4fa902..b23a0536c 100644 --- a/src/groups/bmq/bmqt/bmqt_subscription.h +++ b/src/groups/bmq/bmqt/bmqt_subscription.h @@ -206,6 +206,16 @@ class Subscription { Subscription(const Subscription& other); // MANIPULATORS + /// Assign to this object the value of the specified `rhs` object. + Subscription& operator=(const Subscription& rhs); + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) + /// Assign to this object the value of the specified `rhs` object. + /// After performing this action, the `rhs` object will be left in a + /// valid, but unspecified state. + Subscription& operator=(Subscription&& rhs); +#endif /// Set the maxUnconfirmedMessages to the specified `value`. The /// behavior is undefined unless `value >= 0`. If the specified `value` @@ -276,9 +286,9 @@ bsl::ostream& operator<<(bsl::ostream& stream, const Subscription& rhs); // INLINE DEFINITIONS // ============================================================================ -// ---------------------- +// ------------------------- // class Subscription_Handle -// ---------------------- +// ------------------------- inline SubscriptionHandle::SubscriptionHandle() : d_id(k_INVALID_HANDLE_ID) @@ -385,9 +395,9 @@ inline bsl::ostream& SubscriptionExpression::print(bsl::ostream& stream, return stream; } -// ---------------------- +// ------------------ // class Subscription -// ---------------------- +// ------------------ inline Subscription::Subscription() : d_maxUnconfirmedMessages() @@ -428,6 +438,27 @@ Subscription::print(bsl::ostream& stream, int level, int spacesPerLevel) const } // MANIPULATORS +inline Subscription& Subscription::operator=(const Subscription& rhs) +{ + d_maxUnconfirmedMessages = rhs.d_maxUnconfirmedMessages; + d_maxUnconfirmedBytes = rhs.d_maxUnconfirmedBytes; + d_consumerPriority = rhs.d_consumerPriority; + d_expression = rhs.d_expression; + return *this; +} + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) +inline Subscription& Subscription::operator=(Subscription&& rhs) +{ + d_maxUnconfirmedMessages = bsl::move(rhs.d_maxUnconfirmedMessages); + d_maxUnconfirmedBytes = bsl::move(rhs.d_maxUnconfirmedBytes); + d_consumerPriority = bsl::move(rhs.d_consumerPriority); + d_expression = bsl::move(rhs.d_expression); + return *this; +} +#endif + inline Subscription& Subscription::setMaxUnconfirmedMessages(int value) { d_maxUnconfirmedMessages.emplace(value); From c82fe8865c39f736714cb1aa02bee169fdab4ecc Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Tue, 23 Jul 2024 15:58:10 +0100 Subject: [PATCH 2/2] Allow implicit copy and assignment for bmqt::Subscription Signed-off-by: Evgeny Malygin --- src/groups/bmq/bmqt/bmqt_subscription.h | 49 +------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/src/groups/bmq/bmqt/bmqt_subscription.h b/src/groups/bmq/bmqt/bmqt_subscription.h index b23a0536c..80fef4db2 100644 --- a/src/groups/bmq/bmqt/bmqt_subscription.h +++ b/src/groups/bmq/bmqt/bmqt_subscription.h @@ -197,26 +197,9 @@ class Subscription { public: // CREATORS + /// Create a new Subscription Subscription(); - // Create a new Subscription - - /// Create a new Subscription by copying values from the specified - /// `other`. - Subscription(const Subscription& other); - - // MANIPULATORS - /// Assign to this object the value of the specified `rhs` object. - Subscription& operator=(const Subscription& rhs); - -#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ - defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) - /// Assign to this object the value of the specified `rhs` object. - /// After performing this action, the `rhs` object will be left in a - /// valid, but unspecified state. - Subscription& operator=(Subscription&& rhs); -#endif - /// Set the maxUnconfirmedMessages to the specified `value`. The /// behavior is undefined unless `value >= 0`. If the specified `value` /// is set to 0, it means that the consumer does not receive any @@ -408,15 +391,6 @@ inline Subscription::Subscription() // NOTHING } -inline Subscription::Subscription(const Subscription& other) -: d_maxUnconfirmedMessages(other.d_maxUnconfirmedMessages) -, d_maxUnconfirmedBytes(other.d_maxUnconfirmedBytes) -, d_consumerPriority(other.d_consumerPriority) -, d_expression(other.d_expression) -{ - // NOTHING -} - inline bsl::ostream& Subscription::print(bsl::ostream& stream, int level, int spacesPerLevel) const { @@ -438,27 +412,6 @@ Subscription::print(bsl::ostream& stream, int level, int spacesPerLevel) const } // MANIPULATORS -inline Subscription& Subscription::operator=(const Subscription& rhs) -{ - d_maxUnconfirmedMessages = rhs.d_maxUnconfirmedMessages; - d_maxUnconfirmedBytes = rhs.d_maxUnconfirmedBytes; - d_consumerPriority = rhs.d_consumerPriority; - d_expression = rhs.d_expression; - return *this; -} - -#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ - defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) -inline Subscription& Subscription::operator=(Subscription&& rhs) -{ - d_maxUnconfirmedMessages = bsl::move(rhs.d_maxUnconfirmedMessages); - d_maxUnconfirmedBytes = bsl::move(rhs.d_maxUnconfirmedBytes); - d_consumerPriority = bsl::move(rhs.d_consumerPriority); - d_expression = bsl::move(rhs.d_expression); - return *this; -} -#endif - inline Subscription& Subscription::setMaxUnconfirmedMessages(int value) { d_maxUnconfirmedMessages.emplace(value);