From a3ea40d9324d01b28e50652ff4b489cf78a238a2 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 19 May 2014 17:38:23 -0700 Subject: [PATCH 1/3] Support C++11 minimal allocators --- bitset_test.hpp | 5 ++++ dyn_bitset_unit_tests1.cpp | 33 +++++++++++++++++++++++++ dynamic_bitset.html | 5 ++++ include/boost/detail/dynamic_bitset.hpp | 28 +++++++++++++++------ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/bitset_test.hpp b/bitset_test.hpp index 03051a3..3d17db3 100644 --- a/bitset_test.hpp +++ b/bitset_test.hpp @@ -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) diff --git a/dyn_bitset_unit_tests1.cpp b/dyn_bitset_unit_tests1.cpp index 4cfd19b..9d63131 100644 --- a/dyn_bitset_unit_tests1.cpp +++ b/dyn_bitset_unit_tests1.cpp @@ -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 + +template +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(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 > Bitset; + Bitset b; + bitset_test::max_size(b); + } +#endif } int diff --git a/dynamic_bitset.html b/dynamic_bitset.html index d3c226a..7d340fa 100644 --- a/dynamic_bitset.html +++ b/dynamic_bitset.html @@ -1571,6 +1571,7 @@ exception guarantee.
  • Support for C++11 move constructors.
  • Warning fixes on MSVC 2013.
  • +
  • Support for C++11 minimal allocators.

Changes in Boost 1.37.0

@@ -1666,6 +1667,10 @@ href="mailto:cda@freshsources.com">cda@freshsources.com)
Copyright © 2014 Ahmed Charles (acharles@outlook.com) + +Copyright © 2014 +Glen Fernandes (glenfe@live.com) +
diff --git a/include/boost/detail/dynamic_bitset.hpp b/include/boost/detail/dynamic_bitset.hpp index 281aa55..e0f675d 100644 --- a/include/boost/detail/dynamic_bitset.hpp +++ b/include/boost/detail/dynamic_bitset.hpp @@ -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 #include #include "boost/config.hpp" #include "boost/detail/workaround.hpp" @@ -155,17 +159,25 @@ namespace boost { // meaningful info. // template - 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_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 From 18eb52eceef0203f38976630c50c193fd974edd7 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 19 May 2014 17:39:39 -0700 Subject: [PATCH 2/3] Add noexcept specifications --- dynamic_bitset.html | 11 ++++--- .../boost/dynamic_bitset/dynamic_bitset.hpp | 31 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/dynamic_bitset.html b/dynamic_bitset.html index 7d340fa..d03a502 100644 --- a/dynamic_bitset.html +++ b/dynamic_bitset.html @@ -207,17 +207,17 @@ public: bool any() const; bool none() const; dynamic_bitset operator~() const; - size_type count() const; + size_type count() const noexcept; reference operator[](size_type pos); bool operator[](size_type pos) const; 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 noexcept; + size_type num_blocks() const noexcept; + size_type max_size() const noexcept; + bool empty() const noexcept; bool is_subset_of(const dynamic_bitset& a) const; bool is_proper_subset_of(const dynamic_bitset& a) const; @@ -1572,6 +1572,7 @@ exception guarantee.
  • Support for C++11 move constructors.
  • Warning fixes on MSVC 2013.
  • Support for C++11 minimal allocators.
  • +
  • Add noexcept specifications.
  • Changes in Boost 1.37.0

    diff --git a/include/boost/dynamic_bitset/dynamic_bitset.hpp b/include/boost/dynamic_bitset/dynamic_bitset.hpp index 7bd253d..9e7cbb6 100644 --- a/include/boost/dynamic_bitset/dynamic_bitset.hpp +++ b/include/boost/dynamic_bitset/dynamic_bitset.hpp @@ -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) @@ -286,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) { @@ -296,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; @@ -349,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(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(pos % bits_per_block); } + static Block bit_mask(size_type pos) BOOST_NOEXCEPT { return Block(1) << bit_index(pos); } template void init_from_string(const std::basic_string& s, @@ -1072,7 +1075,7 @@ dynamic_bitset::operator~() const template typename dynamic_bitset::size_type -dynamic_bitset::count() const +dynamic_bitset::count() const BOOST_NOEXCEPT { using detail::dynamic_bitset_impl::table_width; using detail::dynamic_bitset_impl::access_by_bytes; @@ -1206,21 +1209,21 @@ to_ulong() const template inline typename dynamic_bitset::size_type -dynamic_bitset::size() const +dynamic_bitset::size() const BOOST_NOEXCEPT { return m_num_bits; } template inline typename dynamic_bitset::size_type -dynamic_bitset::num_blocks() const +dynamic_bitset::num_blocks() const BOOST_NOEXCEPT { return m_bits.size(); } template inline typename dynamic_bitset::size_type -dynamic_bitset::max_size() const +dynamic_bitset::max_size() const BOOST_NOEXCEPT { // Semantics of vector<>::max_size() aren't very clear // (see lib issue 197) and many library implementations @@ -1241,7 +1244,7 @@ dynamic_bitset::max_size() const } template -inline bool dynamic_bitset::empty() const +inline bool dynamic_bitset::empty() const BOOST_NOEXCEPT { return size() == 0; } From 083c5e6214191928c478f418191a344bc07004d7 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 19 May 2014 17:41:50 -0700 Subject: [PATCH 3/3] Use non-deprecated macro for r-value reference support detection --- bitset_test.hpp | 4 ++-- dyn_bitset_unit_tests1.cpp | 4 ++-- include/boost/dynamic_bitset/dynamic_bitset.hpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bitset_test.hpp b/bitset_test.hpp index 3d17db3..ac47c04 100644 --- a/bitset_test.hpp +++ b/bitset_test.hpp @@ -289,7 +289,7 @@ struct bitset_test { BOOST_CHECK(b.max_size() > 0); } -#ifndef BOOST_NO_RVALUE_REFERENCES +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES // move constructor (absent from std::bitset) static void move_constructor(const Bitset& b) @@ -308,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) { diff --git a/dyn_bitset_unit_tests1.cpp b/dyn_bitset_unit_tests1.cpp index 9d63131..31299d1 100644 --- a/dyn_bitset_unit_tests1.cpp +++ b/dyn_bitset_unit_tests1.cpp @@ -287,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 { @@ -326,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 { diff --git a/include/boost/dynamic_bitset/dynamic_bitset.hpp b/include/boost/dynamic_bitset/dynamic_bitset.hpp index 9e7cbb6..4d6011c 100644 --- a/include/boost/dynamic_bitset/dynamic_bitset.hpp +++ b/include/boost/dynamic_bitset/dynamic_bitset.hpp @@ -216,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; @@ -648,7 +648,7 @@ operator=(const dynamic_bitset& b) return *this; } -#ifndef BOOST_NO_RVALUE_REFERENCES +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template inline dynamic_bitset:: @@ -674,7 +674,7 @@ operator=(dynamic_bitset&& b) return *this; } -#endif // BOOST_NO_RVALUE_REFERENCES +#endif // BOOST_NO_CXX11_RVALUE_REFERENCES template inline typename dynamic_bitset::allocator_type