mirror of
https://github.com/boostorg/container.git
synced 2026-01-25 16:52:48 +01:00
Make static_vector<T, N>'s destructor trivial if T is trivial.
This commit is contained in:
@@ -1437,6 +1437,7 @@ use [*Boost.Container]? There are several reasons for that:
|
||||
[section:release_notes_boost_1_91_00 Boost 1.91 Release]
|
||||
|
||||
* Implemented heterogeneous overloads from C++23 ([@http://wg21.link/p2077r3 P2077]) and C++26 ([@http://wg21.link/P2363 P2363]).
|
||||
* In C++20 compilers, `static_vector<T>`'s destructor is now trivial if `T` is trivial.
|
||||
* Fixed bugs/issues:
|
||||
* [@https://github.com/boostorg/container/issues/323 GitHub #323: ['"flat_tree::try_emplace UB"]].
|
||||
|
||||
@@ -1447,7 +1448,7 @@ use [*Boost.Container]? There are several reasons for that:
|
||||
* Reimplemented [classref boost::container::deque]. The original implementation was based on
|
||||
the SGI's original data structure (similar to libstdc++). Main changes:
|
||||
* `sizeof(deque)` was 10 words, now is 4 words. Probably the lightest implementation around.
|
||||
* `sizeof(deque::iterator)` was 4 words, now is is 2 words (similar to libc++ and MSVC).)
|
||||
* `sizeof(deque::iterator)` was 4 words, now is is 2 words (similar to libc++ and MSVC).
|
||||
* Several internal algorithms were reimplemented to speed up the segmented nature of deque.
|
||||
* Defaults were slightly changed, 64 bit platforms now use 1024 byte blocks by default
|
||||
instead of classic SGI 512 byte blocks.
|
||||
|
||||
@@ -242,4 +242,8 @@ namespace boost {
|
||||
#define BOOST_CONTAINER_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED
|
||||
#endif
|
||||
|
||||
#if defined(__cpp_concepts) && (__cpp_concepts >= 202002L)
|
||||
# define BOOST_CONTAINER_CONCEPTS_BASED_OVERLOADING
|
||||
#endif
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP
|
||||
|
||||
@@ -1223,12 +1223,22 @@ private:
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the number of elements.
|
||||
~vector() BOOST_NOEXCEPT_OR_NOTHROW
|
||||
#if defined(BOOST_INTRUSIVE_CONCEPTS_BASED_OVERLOADING)
|
||||
requires (dtl::version<allocator_type>::value != 0 || !::boost::move_detail::is_trivially_destructible<T>::value)
|
||||
#endif
|
||||
{
|
||||
boost::container::destroy_alloc_n
|
||||
(this->get_stored_allocator(), this->priv_raw_begin(), this->m_holder.m_size);
|
||||
//vector_alloc_holder deallocates the data
|
||||
}
|
||||
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) && defined(BOOST_INTRUSIVE_CONCEPTS_BASED_OVERLOADING)
|
||||
//Default destructor for normal links (allows conditional triviality)
|
||||
~vector()
|
||||
requires (dtl::version<allocator_type>::value == 0 && ::boost::move_detail::is_trivially_destructible<T>::value)
|
||||
= default;
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Makes *this contain the same elements as x.
|
||||
//!
|
||||
//! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
|
||||
|
||||
@@ -671,6 +671,35 @@ bool default_init_test()//Test for default initialization
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(BOOST_INTRUSIVE_CONCEPTS_BASED_OVERLOADING)
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template<class T, bool Result>
|
||||
void static_vector_destructor_triviality_impl()
|
||||
{
|
||||
typedef static_vector<T, 10> vector_t;
|
||||
BOOST_CONTAINER_STATIC_ASSERT(( Result == std::is_trivially_destructible_v<vector_t> ));
|
||||
}
|
||||
|
||||
struct non_trivial
|
||||
{
|
||||
non_trivial(){}
|
||||
~non_trivial(){}
|
||||
};
|
||||
|
||||
void static_vector_triviality()
|
||||
{
|
||||
static_vector_destructor_triviality_impl<int, true>();
|
||||
static_vector_destructor_triviality_impl<float, true>();
|
||||
static_vector_destructor_triviality_impl<non_trivial, false>();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void static_vector_triviality(){}
|
||||
|
||||
#endif //BOOST_INTRUSIVE_CONCEPTS_BASED_OVERLOADING
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
@@ -787,6 +816,8 @@ int main(int, char* [])
|
||||
boost::intrusive::test::test_iterator_random< cont_int >(a);
|
||||
}
|
||||
|
||||
static_vector_triviality();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user