Boost logo

Boost-Commit :

From: gennaro.prota_at_[hidden]
Date: 2008-07-13 15:38:48


Author: gennaro_prota
Date: 2008-07-13 15:38:48 EDT (Sun, 13 Jul 2008)
New Revision: 47401
URL: http://svn.boost.org/trac/boost/changeset/47401

Log:
dynamic_bitset: cleaner implementation of to_ulong (which should also avoid some warnings on 64-bit implementations)
Text files modified:
   trunk/boost/dynamic_bitset/dynamic_bitset.hpp | 20 +++++++-------------
   1 files changed, 7 insertions(+), 13 deletions(-)

Modified: trunk/boost/dynamic_bitset/dynamic_bitset.hpp
==============================================================================
--- trunk/boost/dynamic_bitset/dynamic_bitset.hpp (original)
+++ trunk/boost/dynamic_bitset/dynamic_bitset.hpp 2008-07-13 15:38:48 EDT (Sun, 13 Jul 2008)
@@ -1067,29 +1067,23 @@
   // beyond the "allowed" positions
   typedef unsigned long result_type;
 
- /*
- if find_next() did its job correctly we don't need the if
- below, because all bits we care about are in the first block
-
- if (bits_per_block >= ulong_width)
- return static_cast<result_type>(m_bits[0]);
- */
+ const size_type max_size =
+ (std::min)(m_num_bits, static_cast<size_type>(ulong_width));
+
+ const size_type last_block = block_index( max_size - 1 );
 
- size_type last_block = block_index(
- (std::min)( m_num_bits, (size_type)ulong_width ) - 1 );
   result_type result = 0;
   for (size_type i = 0; i <= last_block; ++i) {
 
- assert((size_type)bits_per_block * i < (size_type)ulong_width);
+ const size_type offset = i * bits_per_block;
+ assert( offset < static_cast<size_type>(ulong_width));
 
- unsigned long piece = m_bits[i];
- result |= (piece << (bits_per_block * i));
+ result |= (static_cast<result_type>(m_bits[i]) << offset);
   }
 
   return result;
 }
 
-
 template <typename Block, typename Allocator>
 inline typename dynamic_bitset<Block, Allocator>::size_type
 dynamic_bitset<Block, Allocator>::size() const


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk