Boost C++ Libraries: Ticket #12169: error when copying blocks into a dynamic_bitset with size() not an integral number of bits_per_block https://svn.boost.org/trac10/ticket/12169 <p> Hi, </p> <p> I'm trying to initialize a dynamic_bitset&lt;unsigned char&gt; from a vector of blocks. Here's the code: </p> <pre class="wiki">#include &lt;cstdlib&gt; #include &lt;vector&gt; #include &lt;boost/dynamic_bitset.hpp&gt; typedef boost::dynamic_bitset&lt;unsigned char&gt; BitSet; typedef std::vector&lt;BitSet::block_type&gt; Block; int main(int argc, char* argv[]) { int nbits = atoi( argv[1] ); BitSet bits( nbits ); Block buffer; buffer.resize( bits.num_blocks(), 0xff ); boost::from_block_range(buffer.begin(),buffer.end(), bits ); return 0; } </pre><p> If the bitset size isn't a multiple of sizeof(unsigned char) (here 8), an assert() in ~dynamic_bitset() fails and the process is aborted. </p> <p> For example: </p> <pre class="wiki">% ./a.out 1 a.out: boost-1.60.0/include/boost/dynamic_bitset/dynamic_bitset.hpp:633: ost::dynamic_bitset&lt;Block, Allocator&gt;::~dynamic_bitset() [with Block = unsigned char; Allocator = std::allocator&lt;unsigned ar&gt;]: Assertion `m_check_invariants()' failed. Aborted % ./a.out 8 % ./a.out 15 a.out: boost-1.60.0/boost/dynamic_bitset/dynamic_bitset.hpp:633: ost::dynamic_bitset&lt;Block, Allocator&gt;::~dynamic_bitset() [with Block = unsigned char; Allocator = std::allocator&lt;unsigned ar&gt;]: Assertion `m_check_invariants()' failed. Aborted % ./a.out 16 % </pre><p> I see this with 1.59 &amp; 1.60 using either g++ 4.7.2 or Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) </p> <p> Thanks, Diab </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12169 Trac 1.4.3