Compare commits

...

6 Commits

Author SHA1 Message Date
Glen Fernandes
b59fc97a67 Use core/allocator_access for allocator use 2020-05-25 22:57:13 -04:00
Andrey Semashev
4a38853898 Avoid using deprecated headers to silence compiler warnings. (#56)
The warnings are generated by boost/detail/iterator.hpp and
boost/detail/no_exceptions_support.hpp. Also, updated location of
addressof.hpp.
2020-05-13 06:44:47 -07:00
joprodrigues
54b15ad171 Improvement to m_do_find_from (#55)
Use find_if to inside find next bit
2020-04-26 10:11:36 -04:00
Edward Diener
ffff25ac00 Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. (#54) 2020-04-16 07:47:58 -07:00
Glen Fernandes
3e0107909b Replace Block(~0) with a max_limit<Block>::value 2020-01-22 07:41:06 -05:00
Glen Fernandes
8359a80feb Make DynamicBitset no longer depend on Serialization (#50) 2019-09-30 15:29:43 -04:00
7 changed files with 33 additions and 29 deletions

View File

@@ -34,7 +34,7 @@ namespace boost { namespace detail {
#endif
//
#if (defined __BORLANDC__ && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))) \
#if (defined BOOST_BORLANDC && BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))) \
|| (defined BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
#endif

View File

@@ -20,6 +20,7 @@
#include <cstddef>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include <boost/core/allocator_access.hpp>
#if ((defined(BOOST_MSVC) && (BOOST_MSVC >= 1600)) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
@@ -30,6 +31,14 @@ namespace boost {
namespace detail {
namespace dynamic_bitset_impl {
template<class T>
struct max_limit {
BOOST_STATIC_CONSTEXPR T value = static_cast<T>(-1);
};
template<class T>
BOOST_CONSTEXPR_OR_CONST T max_limit<T>::value;
// Gives (read-)access to the object representation
// of an object of type T (3.9p4). CANNOT be used
// on a base sub-object
@@ -229,14 +238,8 @@ namespace boost {
const allocator_type& alloc = v.get_allocator();
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<allocator_type> allocator_traits;
const typename allocator_traits::size_type alloc_max =
allocator_traits::max_size(alloc);
#else
const typename allocator_type::size_type alloc_max = alloc.max_size();
#endif
typename boost::allocator_size_type<allocator_type>::type alloc_max =
boost::allocator_max_size(alloc);
const typename T::size_type container_max = v.max_size();

View File

@@ -23,6 +23,7 @@
#include <string>
#include <stdexcept>
#include <algorithm>
#include <iterator> // used to implement append(Iter, Iter)
#include <vector>
#include <climits> // for CHAR_BIT
@@ -43,12 +44,11 @@
#include "boost/dynamic_bitset_fwd.hpp"
#include "boost/dynamic_bitset/detail/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/detail/lowest_bit.hpp"
#include "boost/detail/iterator.hpp" // used to implement append(Iter, Iter)
#include "boost/move/move.hpp"
#include "boost/limits.hpp"
#include "boost/static_assert.hpp"
#include "boost/utility/addressof.hpp"
#include "boost/detail/no_exceptions_support.hpp"
#include "boost/core/addressof.hpp"
#include "boost/core/no_exceptions_support.hpp"
#include "boost/throw_exception.hpp"
#include "boost/functional/hash/hash.hpp"
@@ -247,7 +247,7 @@ public:
{
assert(first != last);
block_width_type r = count_extra_bits();
std::size_t d = boost::detail::distance(first, last);
std::size_t d = std::distance(first, last);
m_bits.reserve(num_blocks() + d);
if (r == 0) {
for( ; first != last; ++first)
@@ -267,7 +267,7 @@ public:
void append(BlockInputIterator first, BlockInputIterator last) // strong guarantee
{
if (first != last) {
typename detail::iterator_traits<BlockInputIterator>::iterator_category cat;
typename std::iterator_traits<BlockInputIterator>::iterator_category cat;
m_append(first, last, cat);
}
}
@@ -375,6 +375,7 @@ private:
void m_zero_unused_bits();
bool m_check_invariants() const;
static bool m_not_empty(Block x){ return x != Block(0); };
size_type m_do_find_from(size_type first_block) const;
block_width_type count_extra_bits() const BOOST_NOEXCEPT { return bit_index(size()); }
@@ -384,7 +385,7 @@ private:
static Block bit_mask(size_type first, size_type last) BOOST_NOEXCEPT
{
Block res = (last == bits_per_block - 1)
? static_cast<Block>(~0)
? detail::dynamic_bitset_impl::max_limit<Block>::value
: ((Block(1) << (last + 1)) - 1);
res ^= (Block(1) << first) - 1;
return res;
@@ -406,7 +407,7 @@ private:
}
inline static Block set_block_full(Block) BOOST_NOEXCEPT
{
return static_cast<Block>(~0);
return detail::dynamic_bitset_impl::max_limit<Block>::value;
}
inline static Block reset_block_partial(Block block, size_type first,
size_type last) BOOST_NOEXCEPT
@@ -764,7 +765,7 @@ resize(size_type num_bits, bool value) // strong guarantee
const size_type old_num_blocks = num_blocks();
const size_type required_blocks = calc_num_blocks(num_bits);
const block_type v = value? ~Block(0) : Block(0);
const block_type v = value? detail::dynamic_bitset_impl::max_limit<Block>::value : Block(0);
if (required_blocks != old_num_blocks) {
m_bits.resize(required_blocks, v); // s.g. (copy)
@@ -1045,7 +1046,7 @@ template <typename Block, typename Allocator>
dynamic_bitset<Block, Allocator>&
dynamic_bitset<Block, Allocator>::set()
{
std::fill(m_bits.begin(), m_bits.end(), static_cast<Block>(~0));
std::fill(m_bits.begin(), m_bits.end(), detail::dynamic_bitset_impl::max_limit<Block>::value);
m_zero_unused_bits();
return *this;
}
@@ -1138,7 +1139,7 @@ bool dynamic_bitset<Block, Allocator>::all() const
}
const block_width_type extra_bits = count_extra_bits();
block_type const all_ones = static_cast<Block>(~0);
block_type const all_ones = detail::dynamic_bitset_impl::max_limit<Block>::value;
if (extra_bits == 0) {
for (size_type i = 0, e = num_blocks(); i < e; ++i) {
@@ -1441,15 +1442,14 @@ bool dynamic_bitset<Block, Allocator>::intersects(const dynamic_bitset & b) cons
// look for the first bit "on", starting
// from the block with index first_block
//
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::m_do_find_from(size_type first_block) const
{
size_type i = first_block;
// skip null blocks
while (i < num_blocks() && m_bits[i] == 0)
++i;
size_type i = std::distance(m_bits.begin(),
std::find_if(m_bits.begin() + first_block, m_bits.end(), m_not_empty) );
if (i >= num_blocks())
return npos; // not found
@@ -2107,7 +2107,7 @@ bool dynamic_bitset<Block, Allocator>::m_check_invariants() const
{
const block_width_type extra_bits = count_extra_bits();
if (extra_bits > 0) {
const block_type mask = block_type(~0) << extra_bits;
const block_type mask = detail::dynamic_bitset_impl::max_limit<Block>::value << extra_bits;
if ((m_highest_block() & mask) != 0)
return false;
}

View File

@@ -12,7 +12,7 @@
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
#include <boost/serialization/vector.hpp>
#include <boost/core/nvp.hpp>
namespace boost {
@@ -23,8 +23,8 @@ namespace boost {
public:
template <typename Ar>
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
ar & serialization::make_nvp("m_num_bits", bs.m_num_bits)
& serialization::make_nvp("m_bits", bs.m_bits);
ar & boost::make_nvp("m_num_bits", bs.m_num_bits)
& boost::make_nvp("m_bits", bs.m_bits);
}
};

View File

@@ -34,7 +34,7 @@ template <typename Block>
inline bool nth_bit(Block num, std::size_t n)
{
#ifndef NDEBUG
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
// Borland deduces Block as a const qualified type,
// and thus finds numeric_limits<Block> to be zero :(
// (though not directly relevant here, see also

View File

@@ -191,7 +191,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
// (in Tests::stream_extractor instantiation)
#if !(defined __BORLANDC__ \
#if !(defined BOOST_BORLANDC \
&& BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)))
// Borland 5.5.1 with RW library crashes
// empty string

View File

@@ -31,6 +31,7 @@
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
#endif
#include <boost/serialization/vector.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>