std::vector< char > get_block( std::vector<char>::const_iterator prefix_begin, std::vector<char>::const_iterator prefix_end, const From &from_string, typename From::size_type head_pos ) { typename From::size_type block_size = std::min( from_string.size() * sizeof( typename From::value_type ) - head_pos, block_size ); std::vector< char > block( prefix_begin, prefix_end ); block.resize( block.size() + block_size ); std::vector< char >::iterator output_head = block.begin(); std::advance( output_head, std::distance( prefix_begin, prefix_end ) ); std::copy( reinterpret_cast<const char*>( from_string.c_str() ) + head_pos, reinterpret_cast<const char*>( from_string.c_str() ) + head_pos + block_size, output_head ); return block; }