diff --git a/.gitignore b/.gitignore index d9a49e4..d388948 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ /bench/detail/hash_table.hpp /Bin/ /include/boost/container/new_deque.hpp +/test/new_deque_test.cpp diff --git a/README.md b/README.md index 4c8c4e0..d6d65fd 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,10 @@ Distributed under the [Boost Software License, Version 1.0](http://www.boost.org ### Build Status -Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | -:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | -[`master`](https://github.com/boostorg/container/tree/master) | [![Build Status](https://travis-ci.org/boostorg/container.svg?branch=master)](https://travis-ci.org/boostorg/container) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/container-0k1xg/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-container) | [![codecov](https://codecov.io/gh/boostorg/container/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/container/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/container.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](https://regression.boost.io/master/developer/container.html) -[`develop`](https://github.com/boostorg/container/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/container.svg?branch=develop)](https://travis-ci.org/boostorg/container) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/container-0k1xg/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-container) | [![codecov](https://codecov.io/gh/boostorg/container/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/container/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/container.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](https://regression.boost.io/develop/developer/container.html) +Branch | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/container/tree/master) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/container-0k1xg/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-container) | [![codecov](https://codecov.io/gh/boostorg/container/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/container/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/container.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](https://regression.boost.io/master/developer/container.html) +[`develop`](https://github.com/boostorg/container/tree/develop) | [![Build status](https://ci.appveyor.com/api/projects/status/9ckrveolxsonxfnb/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/container-0k1xg/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16048/badge.svg)](https://scan.coverity.com/projects/boostorg-container) | [![codecov](https://codecov.io/gh/boostorg/container/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/container/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/container.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/container.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](https://regression.boost.io/develop/developer/container.html) ### Directories diff --git a/bench/bench_vectors.cpp b/bench/bench_vectors.cpp index 8c8a65a..7599de9 100644 --- a/bench/bench_vectors.cpp +++ b/bench/bench_vectors.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "new_deque.hpp" #include #include #include @@ -93,8 +94,9 @@ struct capacity_wrapper { } }; -const std::size_t RangeSize = 5; +const std::size_t RangeSize = 8; +template struct insert_end_range { inline std::size_t capacity_multiplier() const @@ -105,11 +107,12 @@ struct insert_end_range { c.insert(c.end(), &a[0], &a[0]+RangeSize); } const char *name() const - { return "insert_end_range"; } + { return "insert_end_range(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct insert_end_repeated { inline std::size_t capacity_multiplier() const @@ -117,14 +120,15 @@ struct insert_end_repeated template inline void operator()(C &c, int i) - { c.insert(c.end(), RangeSize, MyInt(i)); } + { c.insert(c.end(), RangeSize, IntType(i)); } inline const char *name() const - { return "insert_end_repeated"; } + { return "insert_end_repeated(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct push_back { inline std::size_t capacity_multiplier() const @@ -132,12 +136,13 @@ struct push_back template inline void operator()(C &c, int i) - { c.push_back(MyInt(i)); } + { c.push_back(IntType(i)); } inline const char *name() const { return "push_back"; } }; +template struct emplace_back { inline std::size_t capacity_multiplier() const @@ -151,6 +156,7 @@ struct emplace_back { return "emplace_back"; } }; +template struct insert_near_end_repeated { inline std::size_t capacity_multiplier() const @@ -158,12 +164,13 @@ struct insert_near_end_repeated template inline void operator()(C &c, int i) - { c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), RangeSize, MyInt(i)); } + { c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), RangeSize, IntType(i)); } inline const char *name() const - { return "insert_near_end_repeated"; } + { return "insert_near_end_repeated(8)"; } }; +template struct insert_near_end_range { inline std::size_t capacity_multiplier() const @@ -176,11 +183,12 @@ struct insert_near_end_range } inline const char *name() const - { return "insert_near_end_range"; } + { return "insert_near_end_range(8)"; } - MyInt a[RangeSize]; + IntType a[RangeSize]; }; +template struct insert_near_end { inline std::size_t capacity_multiplier() const @@ -192,13 +200,14 @@ struct insert_near_end typedef typename C::iterator it_t; it_t it (c.end()); it -= static_cast(c.size() >= 2)*2; - c.insert(it, MyInt(i)); + c.insert(it, IntType(i)); } inline const char *name() const { return "insert_near_end"; } }; +template struct emplace_near_end { inline std::size_t capacity_multiplier() const @@ -272,7 +281,7 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, nanosecond_type nseconds = timer.elapsed().wall; - std::cout << cont_name << "->" << op.name() <<" ns: " + std::cout << cont_name << "->" << " ns: " << std::setw(8) << float(nseconds)/float((num_iterations-1)*num_elements) << '\t' @@ -280,8 +289,8 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, << std::endl; } -template -void test_vectors() +template +void test_vectors_impl() { //#define SINGLE_TEST #define SIMPLE_IT @@ -293,7 +302,11 @@ void test_vectors() #endif std::size_t numele [] = { 100000 }; #elif defined SIMPLE_IT + #ifdef NDEBUG + std::size_t numit [] = { 50 }; + #else std::size_t numit [] = { 10 }; + #endif std::size_t numele [] = { 100000 }; #else #ifdef NDEBUG @@ -304,42 +317,69 @@ void test_vectors() unsigned int numele [] = { 10000, 1000, 100, 10 }; #endif - //#define PRERESERVE_ONLY - #ifdef PRERESERVE_ONLY - #define P_INIT 1 - #else - #define P_INIT 0 - #endif - for (unsigned p = P_INIT; p != 2; ++p) { - std::cout << Operation().name() << ", prereserve: " << (p ? "1" : "0") << "\n" << std::endl; - const bool bp =p != 0; - for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){ - vector_test_template< std::vector >, Operation >(numit[i], numele[i], "std::vector ", bp); - vector_test_template< bc::vector >, Operation >(numit[i], numele[i] , "vector ", bp); - vector_test_template< bc::small_vector >, Operation >(numit[i], numele[i], "small_vector ", bp); - vector_test_template< bc::devector >, Operation >(numit[i], numele[i], "devector ", bp); - //vector_test_template< std::deque >, Operation >(numit[i], numele[i], "std::deque ", bp); - vector_test_template< bc::deque >, Operation >(numit[i], numele[i], "deque ", bp); +#define RESERVE_ONLY 0 +#define NORESERVE_ONLY 1 + +//#define RESERVE_STRATEGY NORESERVE_ONLY +#define RESERVE_STRATEGY RESERVE_ONLY + +#ifndef RESERVE_STRATEGY + #define P_INIT 0 + #define P_END 2 +#elif RESERVE_STRATEGY == PRERESERVE_ONLY + #define P_INIT 1 + #define P_END 2 +#elif RESERVE_STRATEGY == NORESERVE_ONLY + #define P_INIT 0 + #define P_END 1 +#endif + + for (unsigned p = P_INIT; p != P_END; ++p) { + std::cout << "---------------------------------\n"; + std::cout << "IntType:" << typeid(IntType).name() << " op:" << Operation().name() << ", prereserve: " << (p ? "1" : "0") << "\n"; + std::cout << "---------------------------------\n"; + const bool bp = p != 0; + const std::size_t it_count = sizeof(numele)/sizeof(numele[0]); + for(unsigned int i = 0; i < it_count; ++i){ + std::cout << "\n" << " ---- numit[i]: " << numit[i] << " numele[i] : " << numele[i] << " ---- \n"; + vector_test_template< std::vector >, Operation >(numit[i], numele[i], "std::vector ", bp); + vector_test_template< bc::vector >, Operation >(numit[i], numele[i] , "vector ", bp); + vector_test_template< bc::small_vector >, Operation >(numit[i], numele[i], "small_vector ", bp); + vector_test_template< bc::devector >, Operation >(numit[i], numele[i], "devector ", bp); + vector_test_template< std::deque >, Operation >(numit[i], numele[i], "std::deque ", bp); + vector_test_template< bc::deque >, Operation >(numit[i], numele[i], "deque ", bp); + vector_test_template< bc::new_deque >, Operation >(numit[i], numele[i], "new_deque ", bp); } std::cout << "---------------------------------\n---------------------------------\n"; } } -int main() +template +void test_vectors() { //end - test_vectors(); - test_vectors(); - test_vectors(); - //near end - test_vectors(); - test_vectors(); - test_vectors(); + test_vectors_impl >(); #if BOOST_CXX_VERSION >= 201103L - test_vectors(); - test_vectors(); + test_vectors_impl >(); #endif + test_vectors_impl >(); + test_vectors_impl >(); + + //near end + test_vectors_impl >(); + #if BOOST_CXX_VERSION >= 201103L + test_vectors_impl >(); + #endif + test_vectors_impl >(); + test_vectors_impl >(); +} + +int main() +{ + //test_vectors(); + test_vectors(); + return 0; } diff --git a/doc/container.qbk b/doc/container.qbk index d60f6f1..e5d6eeb 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1425,9 +1425,11 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs/issues: * [@https://github.com/boostorg/container/pull/294 GitHub #294: ['"CMake: Add option to use header-only Boost::container"]]. + * [@https://github.com/boostorg/container/issues/300 GitHub #300: ['"Warnings when building with clang-20"]]. * [@https://github.com/boostorg/container/pull/305 GitHub #305: ['"Warnings with -Wstrict-prototypes"]]. * [@https://github.com/boostorg/container/pull/307 GitHub #307: ['"Fix all instances of MSVC warning C4146 (unsigned negation)"]]. * [@https://github.com/boostorg/container/issues/309 GitHub #309: ['"Performance regression of boost::container::static_vector introduced in boost v1.86"]]. + * [@https://github.com/boostorg/container/issues/306 GitHub #306: ['"new_allocator.hpp error: '__cpp_sized_deallocation' is not defined, evaluates to 0 [-Werror,-Wundef]"]]. * [@https://github.com/boostorg/container/issues/310 GitHub #310: ['"flat_map: Mention correct type in documentation of emplace and emplace_hint"]]. [endsect] diff --git a/include/boost/container/allocator.hpp b/include/boost/container/allocator.hpp index 3d82f71..ddb96be 100644 --- a/include/boost/container/allocator.hpp +++ b/include/boost/container/allocator.hpp @@ -116,7 +116,7 @@ class allocator allocator& operator=(const allocator&); BOOST_STATIC_CONSTEXPR unsigned int ForbiddenMask = - BOOST_CONTAINER_ALLOCATE_NEW | BOOST_CONTAINER_EXPAND_BWD | BOOST_CONTAINER_EXPAND_FWD ; + BOOST_CONTAINER_ALLOCATE_NEW | BOOST_CONTAINER_EXPAND_BWD | BOOST_CONTAINER_EXPAND_FWD; //The mask can't disable all the allocation types BOOST_CONTAINER_STATIC_ASSERT(( (AllocationDisableMask & ForbiddenMask) != ForbiddenMask )); diff --git a/include/boost/container/detail/copy_move_algo.hpp b/include/boost/container/detail/copy_move_algo.hpp index 7c7d216..6224003 100644 --- a/include/boost/container/detail/copy_move_algo.hpp +++ b/include/boost/container/detail/copy_move_algo.hpp @@ -228,7 +228,7 @@ inline F memmove(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW const value_type *const end_raw = boost::movelib::iterator_to_raw_pointer(l); if(BOOST_LIKELY(beg_raw != end_raw && dest_raw && beg_raw)){ const std::size_t n = std::size_t(end_raw - beg_raw) ; - std::memmove(dest_raw, beg_raw, sizeof(value_type)*n); + std::memmove(reinterpret_cast(dest_raw), beg_raw, sizeof(value_type)*n); r += static_cast(n); } return r; @@ -800,10 +800,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - copy_n(I f, U n, F r) + copy_n(I f, std::size_t n, F r) { while (n) { --n; @@ -815,10 +814,9 @@ inline typename dtl::disable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::enable_if_memtransfer_copy_assignable::type - copy_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW + copy_n(I f, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW { return dtl::memmove_n(f, n, r); } ////////////////////////////////////////////////////////////////////////////// @@ -829,10 +827,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - copy_n_source(I f, U n, F r) + copy_n_source(I f, std::size_t n, F r) { while (n) { --n; @@ -910,10 +907,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n(I f, U n, F r) + move_n(I f, std::size_t n, F r) { while (n) { --n; @@ -925,13 +921,11 @@ inline typename dtl::disable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::enable_if_memtransfer_copy_assignable::type - move_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW + move_n(I f, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW { return dtl::memmove_n(f, n, r); } - ////////////////////////////////////////////////////////////////////////////// // // move_backward @@ -961,11 +955,82 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type const std::size_t n = boost::container::iterator_udistance(f, l); if (BOOST_LIKELY(n != 0)){ r -= n; - std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(f), sizeof(value_type)*n); + std::memmove(reinterpret_cast((boost::movelib::iterator_to_raw_pointer)(r)), (boost::movelib::iterator_to_raw_pointer)(f), sizeof(value_type)*n); } return r; } +////////////////////////////////////////////////////////////////////////////// +// +// move_backward_n +// +////////////////////////////////////////////////////////////////////////////// + +template + // F models ForwardIterator +inline typename dtl::disable_if_memtransfer_copy_assignable::type + move_backward_n(I l, std::size_t n, F r) +{ + while (n) { + --n; + --l; --r; + *r = ::boost::move(*l); + } + return r; +} + +template + // F models ForwardIterator +inline typename dtl::enable_if_memtransfer_copy_assignable::type + move_backward_n(I l, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW +{ + typedef typename boost::container::iter_value::type value_type; + if (BOOST_LIKELY(n != 0)){ + r -= n; + std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(l) - n, sizeof(value_type)*n); + } + return r; +} + +////////////////////////////////////////////////////////////////////////////// +// +// move_backward_n_source +// +////////////////////////////////////////////////////////////////////////////// + +template + // F models ForwardIterator +inline typename dtl::disable_if_memtransfer_copy_assignable::type + move_backward_n_source(I l, std::size_t n, F r) +{ + while (n) { + --n; + --l; --r; + *r = ::boost::move(*l); + } + return l; +} + +template + // F models ForwardIterator +inline typename dtl::enable_if_memtransfer_copy_assignable::type + move_backward_n_source(I l, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW +{ + typedef typename boost::container::iter_value::type value_type; + + if (BOOST_LIKELY(n != 0)){ + r -= n; + l -= n; + std::memmove((boost::movelib::iterator_to_raw_pointer)(r), l, sizeof(value_type)*n); + } + return l; +} + + ////////////////////////////////////////////////////////////////////////////// // // move_n_source_dest @@ -974,10 +1039,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n_source_dest(I f, U n, F &r) + move_n_source_dest(I f, std::size_t n, F &r) { while (n) { --n; @@ -1002,10 +1066,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n_source(I f, U n, F r) + move_n_source(I f, std::size_t n, F r) { while (n) { --n; @@ -1043,10 +1106,9 @@ inline B move_backward_overlapping(B f, B l, B rl) template // U models unsigned integral constant + ,typename I> // I models InputIterator inline typename dtl::disable_if_trivially_destructible::type - destroy_alloc_n(Allocator &a, I f, U n) + destroy_alloc_n(Allocator &a, I f, std::size_t n) { while(n){ --n; @@ -1057,10 +1119,9 @@ inline typename dtl::disable_if_trivially_destructible::type template // U models unsigned integral constant + ,typename I> // I models InputIterator inline typename dtl::enable_if_trivially_destructible::type - destroy_alloc_n(Allocator &, I, U) + destroy_alloc_n(Allocator &, I, std::size_t) {} ////////////////////////////////////////////////////////////////////////////// diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index 1061446..1346537 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -90,7 +90,7 @@ struct intrusive_list_type , dtl::bi::size_type >::type container_type; - typedef container_type type ; + typedef container_type type; }; } //namespace dtl { diff --git a/include/boost/container/new_allocator.hpp b/include/boost/container/new_allocator.hpp index 1dadb2b..009fce0 100644 --- a/include/boost/container/new_allocator.hpp +++ b/include/boost/container/new_allocator.hpp @@ -163,7 +163,7 @@ class new_allocator void deallocate(pointer ptr, size_type n) BOOST_NOEXCEPT_OR_NOTHROW { (void)n; - # if __cpp_sized_deallocation + # if defined(__cpp_sized_deallocation) ::operator delete((void*)ptr, n * sizeof(T)); #else ::operator delete((void*)ptr); diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index 54ef5bd..70bac81 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -94,7 +94,7 @@ struct intrusive_slist_type , dtl::bi::size_type >::type container_type; - typedef container_type type ; + typedef container_type type; }; } //namespace dtl { diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index aecb7dd..5b14239 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -454,16 +454,16 @@ struct vector_alloc_holder } } - inline void set_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void set_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW { this->m_size = static_cast(s); } - inline void dec_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void dec_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW { this->m_size = static_cast(this->m_size - s); } - inline void inc_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void inc_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW { this->m_size = static_cast(this->m_size + s); } - inline void set_stored_capacity(size_type c) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void set_stored_capacity(size_type c) BOOST_NOEXCEPT_OR_NOTHROW { this->m_capacity = static_cast(c); } inline pointer allocation_command(boost::container::allocation_type command, @@ -546,13 +546,13 @@ struct vector_alloc_holder inline const allocator_type &alloc() const BOOST_NOEXCEPT_OR_NOTHROW { return *this; } - inline pointer start() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE pointer start() const BOOST_NOEXCEPT_OR_NOTHROW { return m_start; } - inline size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW { return m_capacity; } - inline void start(const pointer &p) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void start(const pointer &p) BOOST_NOEXCEPT_OR_NOTHROW { m_start = p; } - inline void capacity(const size_type &c) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE void capacity(const size_type &c) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT( c <= stored_size_type(-1)); this->set_stored_capacity(c); } static inline void on_capacity_overflow() @@ -729,13 +729,13 @@ struct vector_alloc_holder inline const allocator_type &alloc() const BOOST_NOEXCEPT_OR_NOTHROW { return *this; } - inline bool try_expand_fwd(size_type at_least) + BOOST_CONTAINER_FORCEINLINE bool try_expand_fwd(size_type at_least) { return !at_least; } - inline pointer start() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE pointer start() const BOOST_NOEXCEPT_OR_NOTHROW { return allocator_type::internal_storage(); } - inline size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW { return allocator_type::internal_capacity; } stored_size_type m_size; @@ -2573,7 +2573,7 @@ private: new_values_destroyer.release(); } - inline bool room_enough() const + BOOST_CONTAINER_FORCEINLINE bool room_enough() const { return this->m_holder.m_size != this->m_holder.capacity(); } inline pointer back_ptr() const @@ -2897,13 +2897,13 @@ private: } template - inline iterator priv_insert(const const_iterator &p, BOOST_FWD_REF(U) u) + BOOST_CONTAINER_FORCEINLINE iterator priv_insert(const const_iterator &p, BOOST_FWD_REF(U) u) { return this->emplace(p, ::boost::forward(u)); } template - inline void priv_push_back(BOOST_FWD_REF(U) u) + BOOST_CONTAINER_FORCEINLINE void priv_push_back(BOOST_FWD_REF(U) u) { this->emplace_back(::boost::forward(u)); } @@ -3014,6 +3014,7 @@ private: { return alloc_holder_t::on_capacity_overflow(), iterator(); } + #ifdef _MSC_VER #pragma warning (pop) #endif @@ -3022,15 +3023,14 @@ private: BOOST_CONTAINER_NOINLINE iterator priv_insert_forward_range_no_capacity (T *const raw_pos, const size_type n, const InsertionProxy insert_range_proxy, version_1) { - //Check if we have enough memory or try to expand current memory - const size_type n_pos = static_cast(raw_pos - this->priv_raw_begin()); - const size_type new_cap = this->m_holder.template next_capacity(n); //Pass the hint so that allocators can take advantage of this. T * const new_buf = boost::movelib::to_raw_pointer(this->m_holder.allocate(new_cap)); #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS ++this->num_alloc; #endif + //Check if we have enough memory or try to expand current memory + const size_type n_pos = static_cast(raw_pos - this->priv_raw_begin()); this->priv_insert_forward_range_new_allocation(new_buf, new_cap, raw_pos, n, insert_range_proxy); return iterator(this->m_holder.start() + difference_type(n_pos)); } @@ -3221,10 +3221,10 @@ private: } private: - inline T *priv_raw_begin() const + BOOST_CONTAINER_FORCEINLINE T *priv_raw_begin() const { return boost::movelib::to_raw_pointer(m_holder.start()); } - inline T* priv_raw_end() const + BOOST_CONTAINER_FORCEINLINE T* priv_raw_end() const { return this->priv_raw_begin() + this->m_holder.m_size; } template //inline single-element version as it is significantly smaller diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..ea02151 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,100 @@ +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # warning level 4 + add_compile_options(/W4) +endif() + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +if(NOT TARGET tests) + add_custom_target(tests) +endif() + +set(PREFIX "boost_container_") +set(LINK_LIBRARIES Boost::container Boost::included_test_exec_monitor) + +function(boost_container_add_test name source) + set(pname "${PREFIX}${name}") + add_executable(${pname} ${source}) + target_link_libraries(${pname} ${LINK_LIBRARIES}) + add_test(NAME ${pname} COMMAND ${pname}) + add_dependencies(tests ${pname}) +endfunction() + +boost_container_add_test(allocator_traits_test allocator_traits_test.cpp) +boost_container_add_test(alloc_basic_test alloc_basic_test.cpp) +boost_container_add_test(alloc_full_test alloc_full_test.cpp) +boost_container_add_test(boost_iterator_comp_test boost_iterator_comp_test.cpp) +boost_container_add_test(common_iterator_test common_iterator_test.cpp) +boost_container_add_test(copy_move_algo_test copy_move_algo_test.cpp) +boost_container_add_test(deque_options_test deque_options_test.cpp) +boost_container_add_test(deque_test deque_test.cpp) +boost_container_add_test(devector_options_test devector_options_test.cpp) +boost_container_add_test(devector_test devector_test.cpp) +boost_container_add_test(explicit_inst_deque_test explicit_inst_deque_test.cpp) +boost_container_add_test(explicit_inst_devector_test explicit_inst_devector_test.cpp) +boost_container_add_test(explicit_inst_flat_map_test explicit_inst_flat_map_test.cpp) +boost_container_add_test(explicit_inst_flat_set_test explicit_inst_flat_set_test.cpp) +boost_container_add_test(explicit_inst_list_test explicit_inst_list_test.cpp) +boost_container_add_test(explicit_inst_map_test explicit_inst_map_test.cpp) +boost_container_add_test(explicit_inst_set_test explicit_inst_set_test.cpp) +boost_container_add_test(explicit_inst_slist_test explicit_inst_slist_test.cpp) +boost_container_add_test(explicit_inst_small_vector_test explicit_inst_small_vector_test.cpp) +boost_container_add_test(explicit_inst_stable_vector_test explicit_inst_stable_vector_test.cpp) +boost_container_add_test(explicit_inst_static_vector_test explicit_inst_static_vector_test.cpp) +boost_container_add_test(explicit_inst_string_test explicit_inst_string_test.cpp) +boost_container_add_test(explicit_inst_vector_test explicit_inst_vector_test.cpp) +boost_container_add_test(flat_map_adaptor_test flat_map_adaptor_test.cpp) +boost_container_add_test(flat_map_test flat_map_test.cpp) +boost_container_add_test(flat_set_adaptor_test flat_set_adaptor_test.cpp) +boost_container_add_test(flat_set_test flat_set_test.cpp) +boost_container_add_test(flat_tree_test flat_tree_test.cpp) +boost_container_add_test(global_resource_test global_resource_test.cpp) +boost_container_add_test(insert_vs_emplace_test insert_vs_emplace_test.cpp) +boost_container_add_test(list_test list_test.cpp) +boost_container_add_test(map_test map_test.cpp) +boost_container_add_test(memory_resource_test memory_resource_test.cpp) +boost_container_add_test(monotonic_buffer_resource_test monotonic_buffer_resource_test.cpp) +boost_container_add_test(node_handle_test node_handle_test.cpp) +boost_container_add_test(null_iterators_test null_iterators_test.cpp) +boost_container_add_test(pair_test pair_test.cpp) +boost_container_add_test(pmr_deque_test pmr_deque_test.cpp) +boost_container_add_test(pmr_devector_test pmr_devector_test.cpp) +boost_container_add_test(pmr_flat_map_test pmr_flat_map_test.cpp) +boost_container_add_test(pmr_flat_set_test pmr_flat_set_test.cpp) +boost_container_add_test(pmr_list_test pmr_list_test.cpp) +boost_container_add_test(pmr_map_test pmr_map_test.cpp) +boost_container_add_test(pmr_set_test pmr_set_test.cpp) +boost_container_add_test(pmr_slist_test pmr_slist_test.cpp) +boost_container_add_test(pmr_small_vector_test pmr_small_vector_test.cpp) +boost_container_add_test(pmr_stable_vector_test pmr_stable_vector_test.cpp) +boost_container_add_test(pmr_string_test pmr_string_test.cpp) +boost_container_add_test(pmr_vector_test pmr_vector_test.cpp) +boost_container_add_test(polymorphic_allocator_test polymorphic_allocator_test.cpp) +boost_container_add_test(resource_adaptor_test resource_adaptor_test.cpp) +boost_container_add_test(scoped_allocator_adaptor_test scoped_allocator_adaptor_test.cpp) +boost_container_add_test(scoped_allocator_usage_test scoped_allocator_usage_test.cpp) +boost_container_add_test(set_test set_test.cpp) +boost_container_add_test(slist_test slist_test.cpp) +boost_container_add_test(small_vector_options_test small_vector_options_test.cpp) +boost_container_add_test(small_vector_test small_vector_test.cpp) +boost_container_add_test(stable_vector_test stable_vector_test.cpp) +boost_container_add_test(static_vector_options_test static_vector_options_test.cpp) +boost_container_add_test(static_vector_test static_vector_test.cpp) +boost_container_add_test(string_test string_test.cpp) +boost_container_add_test(string_view_compat_test string_view_compat_test.cpp) +boost_container_add_test(synchronized_pool_resource_test synchronized_pool_resource_test.cpp) +boost_container_add_test(throw_exception_test throw_exception_test.cpp) +boost_container_add_test(tree_test tree_test.cpp) +boost_container_add_test(unsynchronized_pool_resource_test unsynchronized_pool_resource_test.cpp) +boost_container_add_test(uses_allocator_test uses_allocator_test.cpp) +boost_container_add_test(vector_options_test vector_options_test.cpp) +boost_container_add_test(vector_test vector_test.cpp) diff --git a/test/allocator_argument_tester.hpp b/test/allocator_argument_tester.hpp index 584d2b7..909204f 100644 --- a/test/allocator_argument_tester.hpp +++ b/test/allocator_argument_tester.hpp @@ -74,7 +74,7 @@ class propagation_test_allocator void deallocate(value_type *ptr, std::size_t n) { (void)n; - # if __cpp_sized_deallocation + # if defined(__cpp_sized_deallocation) ::operator delete((void*)ptr, n * sizeof(value_type)); #else ::operator delete((void*)ptr); diff --git a/test/dummy_test_allocator.hpp b/test/dummy_test_allocator.hpp index 8688647..986c771 100644 --- a/test/dummy_test_allocator.hpp +++ b/test/dummy_test_allocator.hpp @@ -65,7 +65,7 @@ class simple_allocator void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW { (void)n; - # if __cpp_sized_deallocation + # if defined(__cpp_sized_deallocation) ::operator delete((void*)ptr, n * sizeof(T)); #else ::operator delete((void*)ptr); @@ -187,7 +187,7 @@ class propagation_test_allocator void deallocate(T *ptr, std::size_t n) BOOST_NOEXCEPT_OR_NOTHROW { (void)n; - # if __cpp_sized_deallocation + # if defined(__cpp_sized_deallocation) ::operator delete((void*)ptr, n * sizeof(T)); #else ::operator delete((void*)ptr); diff --git a/test/explicit_inst_vector_test.cpp b/test/explicit_inst_vector_test.cpp index fadb651..415761b 100644 --- a/test/explicit_inst_vector_test.cpp +++ b/test/explicit_inst_vector_test.cpp @@ -38,7 +38,7 @@ class CustomAllocator void deallocate(pointer ptr, size_type n) { (void)n; - # if __cpp_sized_deallocation + # if defined(__cpp_sized_deallocation) ::operator delete((void*)ptr, n * sizeof(value_type)); #else ::operator delete((void*)ptr); diff --git a/test/vector_test.hpp b/test/vector_test.hpp index 8b54380..7b3ca81 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -367,6 +367,38 @@ int vector_move_assignable_only(boost::container::dtl::true_type) } if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } + { + //Initialize values + IntType aux_vect[50]; + for(int i = 0; i < 50; ++i){ + aux_vect[i] = -1; + } + int aux_vect2[50]; + for(int i = 0; i < 50; ++i){ + aux_vect2[i] = -1; + } + typename MyBoostVector::iterator insert_it = + boostvector.insert(boostvector.end() + ,boost::make_move_iterator(&aux_vect[0]) + ,boost::make_move_iterator(aux_vect + 50)); + if(boost::container::iterator_udistance(insert_it, boostvector.end()) != 50) return 1; + stdvector.insert(stdvector.end(), aux_vect2, aux_vect2 + 50); + if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; + + boostvector.erase(boostvector.begin(), boostvector.begin() + 5); + stdvector.erase(stdvector.begin(), stdvector.begin()+5); + + boostvector.erase(boostvector.end() - 5, boostvector.end()); + stdvector.erase(stdvector.end() - 5, stdvector.end()); + + boostvector.erase(boostvector.begin()+5, boostvector.begin() + 10); + stdvector.erase(stdvector.begin()+5, stdvector.begin()+10); + + boostvector.erase(boostvector.end() - 10, boostvector.end()-5); + stdvector.erase(stdvector.end() - 10, stdvector.end()-5); + + if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; + } { boostvector.resize(100u); stdvector.resize(100u);