mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Fix append< BlockInputIterator >() for input iterators
We were using `AllocatorOrContainer` as if it were still guaranteed to be an allocator type. Unfortunately, the append() tests didn't exercise input iterators, so this went unnoticed. I've now added tests.
This commit is contained in:
@@ -2145,8 +2145,9 @@ template< typename BlockInputIterator >
|
||||
void
|
||||
dynamic_bitset< Block, AllocatorOrContainer >::m_append( BlockInputIterator first, BlockInputIterator last, std::input_iterator_tag )
|
||||
{
|
||||
std::vector< Block, AllocatorOrContainer > v( first, last );
|
||||
m_append( v.begin(), v.end(), std::random_access_iterator_tag() );
|
||||
for ( ; first != last; ++first ) {
|
||||
append( *first );
|
||||
}
|
||||
}
|
||||
|
||||
template< typename Block, typename AllocatorOrContainer >
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
#include "boost/limits.hpp"
|
||||
#include <algorithm>
|
||||
#include <assert.h> // <cassert> is sometimes macro-guarded :-(
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#if ! defined( BOOST_NO_STD_LOCALE )
|
||||
@@ -528,6 +531,20 @@ struct bitset_test
|
||||
BOOST_TEST( b == c );
|
||||
}
|
||||
|
||||
static void
|
||||
append_block_range_input_iter( const Bitset & lhs )
|
||||
{
|
||||
if ( ! std::is_same< Block, unsigned char >::value ) {
|
||||
Bitset b( lhs ), c( lhs );
|
||||
std::istringstream ss( "1 2 3" );
|
||||
b.append( std::istream_iterator< Block >( ss ), std::istream_iterator< Block >() );
|
||||
c.append( 1 );
|
||||
c.append( 2 );
|
||||
c.append( 3 );
|
||||
BOOST_TEST( b == c );
|
||||
}
|
||||
}
|
||||
|
||||
// operator[] and reference members
|
||||
// PRE: b[i] == bit_vec[i]
|
||||
static void
|
||||
|
||||
@@ -543,6 +543,19 @@ run_test_cases()
|
||||
blocks[ 2 ] = all_1s;
|
||||
Tests::append_block_range( a, blocks );
|
||||
}
|
||||
// Test with input iterators
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( "0" );
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
{
|
||||
bitset_type b( long_string.c_str() );
|
||||
Tests::append_block_range_input_iter( b );
|
||||
}
|
||||
//=====================================================================
|
||||
// Test bracket operator
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user