Skip to content

Commit

Permalink
Apply safe bool idiom
Browse files Browse the repository at this point in the history
Signed-off-by: Vinay Deshmukh <[email protected]>
  • Loading branch information
vinay-deshmukh committed Jan 29, 2025
1 parent 6b34d52 commit 34c58c2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/groups/bmq/bmqa/bmqa_configurequeuestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class ConfigureQueueStatus {
BSLMF_NESTED_TRAIT_DECLARATION(ConfigureQueueStatus,
bslma::UsesBslmaAllocator)

// Use of an `UnspecifiedBool` to prevent implicit conversions to
// integral values, and comparisons between different classes which
// have boolean operators.
typedef bsls::UnspecifiedBool<ConfigureQueueStatus>::BoolType BoolType;

// CREATORS

/// Default constructor, use the optionally specified `allocator`.
Expand Down Expand Up @@ -103,7 +108,7 @@ class ConfigureQueueStatus {
// ACCESSORS

/// Return true if this result indicates success, and false otherwise.
operator bool() const;
operator BoolType() const;

/// Return the queueId associated to this operation result, if any.
const QueueId& queueId() const;
Expand Down Expand Up @@ -198,9 +203,10 @@ ConfigureQueueStatus::operator=(const ConfigureQueueStatus& other)
}

// ACCESSORS
inline ConfigureQueueStatus::operator bool() const
inline ConfigureQueueStatus::operator BoolType() const
{
return result() == bmqt::ConfigureQueueResult::e_SUCCESS;
return bsls::UnspecifiedBool<ConfigureQueueStatus>::makeValue(
result() == bmqt::ConfigureQueueResult::e_SUCCESS);
}

inline const QueueId& ConfigureQueueStatus::queueId() const
Expand Down

0 comments on commit 34c58c2

Please sign in to comment.