How do I change the value of a dynamic_bitset?

389 Views Asked by At

I am using C++ boost's dynamic_bitset.

I have already allocated a variable and I just want to change its value - to construct it anew from an 'unsigned long' like from the constructor, but I don't want to allocate the memory again or to create a temporary variable.

What can I do?

1

There are 1 best solutions below

0
On

I suppose you could clear it and then append the new value:

long x, y;
boost::dynamic_bitset<> bs(sizeof(long)*8, x);
bs.clear();
bs.append(y);