views:

74

answers:

1

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  A: 

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);
UncleBens