mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Support C++11 minimal allocators
This commit is contained in:
@@ -284,6 +284,11 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
static void max_size(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.max_size() > 0);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
|
||||
// move constructor (absent from std::bitset)
|
||||
|
||||
@@ -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]))
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1571,6 +1571,7 @@ 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>
|
||||
</ul>
|
||||
|
||||
<h4><i>Changes in Boost 1.37.0</i></h4>
|
||||
@@ -1666,6 +1667,10 @@ href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Ahmed Charles (<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Glen Fernandes (<a href="mailto:glenfe@live.com">glenfe@live.com</a>)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<div class="legalnotice">
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user