Opened 11 years ago

Closed 9 years ago

#6164 closed Feature Requests (fixed)

Add a function to dynamic_bitset to test and set

Reported by: Chris Kingsley <chris.kingsley@…> Owned by: acharles
Milestone: Boost 1.56.0 Component: dynamic_bitset
Version: Boost 1.48.0 Severity: Not Applicable
Keywords: Cc:

Description

I often use an idiom:

if (!dynBitset.test(pos)) {

dynBitset.set(pos); do a once-only operation

It would be nice to have something like:

if (!dynBitset.test_set(pos)) {

do a once-only operation

Yes, it could be done by saving a temporary reference, but this form is compact and easy to understand.

Attachments (1)

msg1122.txt (1.3 KB ) - added by Chris Kingsley <chris.kingsley@…> 11 years ago.
a diff of current dynamic_bitset.hpp and my changed version

Download all attachments as: .zip

Change History (5)

by Chris Kingsley <chris.kingsley@…>, 11 years ago

Attachment: msg1122.txt added

a diff of current dynamic_bitset.hpp and my changed version

comment:1 by Chris Kingsley <chris.kingsley@…>, 11 years ago

By the way, it might be worth noting that this isn't pretending to be an *atomic* test and set. There are specific machine instructions that do test and set atomically, used for synchronization. I don't think dynamic_bitset should consider being used as a synchronizer, so it shouldn't use the slower atomic operations.

comment:2 by acharles, 9 years ago

Milestone: To Be DeterminedBoost 1.56.0
Owner: changed from jsiek to acharles
Severity: OptimizationNot Applicable
Status: newassigned

comment:3 by acharles, 9 years ago

Fix in develop.

comment:4 by acharles, 9 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.