Merge pull request #9 from boostorg/develop

Merge develop to master

Tested on Darwin, thanks.
This commit is contained in:
Noel Belcourt
2014-06-25 13:27:29 -06:00
5 changed files with 113 additions and 48 deletions

View File

@@ -284,7 +284,12 @@ struct bitset_test {
}
}
#ifndef BOOST_NO_RVALUE_REFERENCES
static void max_size(const Bitset& b)
{
BOOST_CHECK(b.max_size() > 0);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// move constructor (absent from std::bitset)
static void move_constructor(const Bitset& b)
@@ -303,7 +308,7 @@ struct bitset_test {
BOOST_CHECK(b == rhs);
}
#endif // BOOST_NO_RVALUE_REFERENCES
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
static void swap(const Bitset& lhs, const Bitset& rhs)
{

View File

@@ -3,6 +3,9 @@
// Copyright (c) 2003-2006 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -16,6 +19,28 @@
#include "boost/detail/workaround.hpp"
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <cstdlib>
template<class T>
class minimal_allocator {
public:
typedef T value_type;
T* allocate(std::size_t n) {
void* p = std::malloc(sizeof(T) * n);
if (!p) {
throw std::bad_alloc();
}
return static_cast<T*>(p);
}
void deallocate(T* p, std::size_t) {
std::free(p);
}
};
#endif
#define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0]))
@@ -262,7 +287,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
Tests::copy_assignment_operator(a, b);
}
#ifndef BOOST_NO_RVALUE_REFERENCES
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test move constructor
{
@@ -301,7 +326,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
bitset_type b(long_string); // b greater than a
Tests::move_assignment_operator(a, b);
}
#endif // BOOST_NO_RVALUE_REFERENCES
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//=====================================================================
// Test swap
{
@@ -459,6 +484,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
Tests::operator_bracket(b, bit_vec);
}
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
{
typedef boost::dynamic_bitset<Block,
minimal_allocator<Block> > Bitset;
Bitset b;
bitset_test<Bitset>::max_size(b);
}
#endif
}
int

View File

@@ -207,17 +207,17 @@ public:
bool <a href="#any">any</a>() const;
bool <a href="#none">none</a>() const;
dynamic_bitset <a href="#op-not">operator~</a>() const;
size_type <a href="#count">count</a>() const;
size_type <a href="#count">count</a>() const noexcept;
reference <a href="#bracket">operator[]</a>(size_type pos);
bool <a href="#const-bracket">operator[]</a>(size_type pos) const;
unsigned long <a href="#to_ulong">to_ulong</a>() const;
size_type <a href="#size">size</a>() const;
size_type <a href="#num_blocks">num_blocks</a>() const;
size_type <a href="#max_size">max_size</a>() const;
bool <a href="#empty">empty</a>() const;
size_type <a href="#size">size</a>() const noexcept;
size_type <a href="#num_blocks">num_blocks</a>() const noexcept;
size_type <a href="#max_size">max_size</a>() const noexcept;
bool <a href="#empty">empty</a>() const noexcept;
bool <a href="#is_subset_of">is_subset_of</a>(const dynamic_bitset&amp; a) const;
bool <a href="#is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset&amp; a) const;
@@ -1571,6 +1571,8 @@ exception guarantee.
<ul>
<li>Support for C++11 move constructors.</li>
<li>Warning fixes on MSVC 2013.</li>
<li>Support for C++11 minimal allocators.</li>
<li>Add noexcept specifications.</li>
</ul>
<h4><i>Changes in Boost 1.37.0</i></h4>
@@ -1666,6 +1668,10 @@ href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br
<td>Copyright &copy; 2014</td>
<td>Ahmed Charles (<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>)</td>
</tr>
<tr>
<td>Copyright &copy; 2014</td>
<td>Glen Fernandes (<a href="mailto:glenfe@live.com">glenfe@live.com</a>)</td>
</tr>
</table>
<br />
<div class="legalnotice">

View File

@@ -3,6 +3,9 @@
// Copyright (c) 2001-2002 Chuck Allison and Jeremy Siek
// Copyright (c) 2003-2006, 2008 Gennaro Prota
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -12,6 +15,7 @@
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
#include <memory>
#include <cstddef>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
@@ -155,17 +159,25 @@ namespace boost {
// meaningful info.
//
template <typename T>
typename T::size_type vector_max_size_workaround(const T & v) {
inline typename T::size_type vector_max_size_workaround(const T & v)
BOOST_NOEXCEPT
{
typedef typename T::allocator_type allocator_type;
typedef typename T::allocator_type allocator_type;
const allocator_type& alloc = v.get_allocator();
const typename allocator_type::size_type alloc_max =
v.get_allocator().max_size();
const typename T::size_type container_max = v.max_size();
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<allocator_type> allocator_traits;
return alloc_max < container_max?
alloc_max :
container_max;
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
const typename T::size_type container_max = v.max_size();
return alloc_max < container_max ? alloc_max : container_max;
}
// for static_asserts

View File

@@ -4,6 +4,9 @@
// Copyright (c) 2003-2006, 2008 Gennaro Prota
// Copyright (c) 2014 Ahmed Charles
//
// Copyright (c) 2014 Glen Joseph Fernandes
// glenfe at live dot com
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -42,6 +45,8 @@
#include "boost/pending/lowest_bit.hpp"
#include "boost/static_assert.hpp"
#include "boost/utility/addressof.hpp"
#include "boost/detail/no_exceptions_support.hpp"
#include "boost/throw_exception.hpp"
namespace boost {
@@ -211,10 +216,10 @@ public:
void swap(dynamic_bitset& b);
dynamic_bitset& operator=(const dynamic_bitset& b);
#ifndef BOOST_NO_RVALUE_REFERENCES
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
dynamic_bitset(dynamic_bitset&& src);
dynamic_bitset& operator=(dynamic_bitset&& src);
#endif // BOOST_NO_RVALUE_REFERENCES
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
allocator_type get_allocator() const;
@@ -284,7 +289,7 @@ public:
bool any() const;
bool none() const;
dynamic_bitset operator~() const;
size_type count() const;
size_type count() const BOOST_NOEXCEPT;
// subscript
reference operator[](size_type pos) {
@@ -294,10 +299,10 @@ public:
unsigned long to_ulong() const;
size_type size() const;
size_type num_blocks() const;
size_type max_size() const;
bool empty() const;
size_type size() const BOOST_NOEXCEPT;
size_type num_blocks() const BOOST_NOEXCEPT;
size_type max_size() const BOOST_NOEXCEPT;
bool empty() const BOOST_NOEXCEPT;
bool is_subset_of(const dynamic_bitset& a) const;
bool is_proper_subset_of(const dynamic_bitset& a) const;
@@ -347,10 +352,10 @@ private:
size_type m_do_find_from(size_type first_block) const;
block_width_type count_extra_bits() const { return bit_index(size()); }
static size_type block_index(size_type pos) { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) { return static_cast<block_width_type>(pos % bits_per_block); }
static Block bit_mask(size_type pos) { return Block(1) << bit_index(pos); }
block_width_type count_extra_bits() const BOOST_NOEXCEPT { return bit_index(size()); }
static size_type block_index(size_type pos) BOOST_NOEXCEPT { return pos / bits_per_block; }
static block_width_type bit_index(size_type pos) BOOST_NOEXCEPT { return static_cast<block_width_type>(pos % bits_per_block); }
static Block bit_mask(size_type pos) BOOST_NOEXCEPT { return Block(1) << bit_index(pos); }
template <typename CharT, typename Traits, typename Alloc>
void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s,
@@ -643,7 +648,7 @@ operator=(const dynamic_bitset<Block, Allocator>& b)
return *this;
}
#ifndef BOOST_NO_RVALUE_REFERENCES
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline dynamic_bitset<Block, Allocator>::
@@ -669,7 +674,7 @@ operator=(dynamic_bitset<Block, Allocator>&& b)
return *this;
}
#endif // BOOST_NO_RVALUE_REFERENCES
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::allocator_type
@@ -1070,7 +1075,7 @@ dynamic_bitset<Block, Allocator>::operator~() const
template <typename Block, typename Allocator>
typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::count() const
dynamic_bitset<Block, Allocator>::count() const BOOST_NOEXCEPT
{
using detail::dynamic_bitset_impl::table_width;
using detail::dynamic_bitset_impl::access_by_bytes;
@@ -1179,7 +1184,7 @@ to_ulong() const
// Check for overflows. This may be a performance burden on very
// large bitsets but is required by the specification, sorry
if (find_next(ulong_width - 1) != npos)
throw std::overflow_error("boost::dynamic_bitset::to_ulong overflow");
BOOST_THROW_EXCEPTION(std::overflow_error("boost::dynamic_bitset::to_ulong overflow"));
// Ok, from now on we can be sure there's no "on" bit
@@ -1204,21 +1209,21 @@ to_ulong() const
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::size() const
dynamic_bitset<Block, Allocator>::size() const BOOST_NOEXCEPT
{
return m_num_bits;
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::num_blocks() const
dynamic_bitset<Block, Allocator>::num_blocks() const BOOST_NOEXCEPT
{
return m_bits.size();
}
template <typename Block, typename Allocator>
inline typename dynamic_bitset<Block, Allocator>::size_type
dynamic_bitset<Block, Allocator>::max_size() const
dynamic_bitset<Block, Allocator>::max_size() const BOOST_NOEXCEPT
{
// Semantics of vector<>::max_size() aren't very clear
// (see lib issue 197) and many library implementations
@@ -1239,7 +1244,7 @@ dynamic_bitset<Block, Allocator>::max_size() const
}
template <typename Block, typename Allocator>
inline bool dynamic_bitset<Block, Allocator>::empty() const
inline bool dynamic_bitset<Block, Allocator>::empty() const BOOST_NOEXCEPT
{
return size() == 0;
}
@@ -1500,7 +1505,7 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
const Ch zero = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '0');
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
try {
BOOST_TRY {
typedef typename dynamic_bitset<Block, Alloc>::size_type bitset_size_type;
typedef basic_streambuf<Ch, Tr> buffer_type;
@@ -1547,13 +1552,14 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
os.width(0);
} catch (...) { // see std 27.6.1.1/4
} BOOST_CATCH (...) { // see std 27.6.1.1/4
bool rethrow = false;
try { os.setstate(ios_base::failbit); } catch (...) { rethrow = true; }
BOOST_TRY { os.setstate(ios_base::failbit); } BOOST_CATCH (...) { rethrow = true; } BOOST_CATCH_END
if (rethrow)
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
if(err != ok)
@@ -1612,13 +1618,14 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
break; // non digit character
else {
try {
BOOST_TRY {
appender.do_append(char(c) == '1');
}
catch(...) {
BOOST_CATCH(...) {
is.setstate(std::ios::failbit); // assume this can't throw
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
} // for
@@ -1659,7 +1666,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
const Ch one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
b.clear();
try {
BOOST_TRY {
typename bitset_type::bit_appender appender(b);
basic_streambuf <Ch, Tr> * buf = is.rdbuf();
typename Tr::int_type c = buf->sgetc();
@@ -1682,7 +1689,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
} // for
}
catch (...) {
BOOST_CATCH (...) {
// catches from stream buf, or from vector:
//
// bits_stored bits have been extracted and stored, and
@@ -1690,13 +1697,15 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
// append to the underlying vector (out of memory)
bool rethrow = false; // see std 27.6.1.1/4
try { is.setstate(ios_base::badbit); }
catch(...) { rethrow = true; }
BOOST_TRY { is.setstate(ios_base::badbit); }
BOOST_CATCH(...) { rethrow = true; }
BOOST_CATCH_END
if (rethrow)
throw;
BOOST_RETHROW;
}
BOOST_CATCH_END
}
is.width(0);