Skip to content

Commit

Permalink
Apply patch to list from move to C++17.
Browse files Browse the repository at this point in the history
  • Loading branch information
CLIDragon committed Jan 5, 2025
1 parent ab9e4c3 commit 07fa229
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@
#define LIST_BLOCK_MIN static_cast<group_size_type>((sizeof(node) * 8 > (sizeof(*this) + sizeof(group)) * 2) ? 8 : (((sizeof(*this) + sizeof(group)) * 2) / sizeof(node)) + 1)
#define LIST_BLOCK_MAX 2048

#define LIST_CONSTEXPR
#define LIST_NOEXCEPT_SWAP(the_allocator) noexcept
#define LIST_NOEXCEPT_MOVE_ASSIGNMENT(the_allocator) noexcept

// TODO: Switch to these when we move to C++17
// #define LIST_CONSTEXPR constexpr
// #define LIST_NOEXCEPT_SWAP(the_allocator) noexcept(std::allocator_traits<the_allocator>::propagate_on_container_swap::value)
// #define LIST_NOEXCEPT_MOVE_ASSIGNMENT(the_allocator) noexcept(std::allocator_traits<the_allocator>::is_always_equal::value)
#define LIST_CONSTEXPR constexpr
#define LIST_NOEXCEPT_SWAP(the_allocator) noexcept(std::allocator_traits<the_allocator>::propagate_on_container_swap::value)
#define LIST_NOEXCEPT_MOVE_ASSIGNMENT(the_allocator) noexcept(std::allocator_traits<the_allocator>::is_always_equal::value)

// Note: GCC creates faster code without forcing inline
#if defined(_MSC_VER)
Expand Down Expand Up @@ -185,7 +180,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
nodes = std::move( source.nodes );
free_list_head = std::move( source.free_list_head );
beyond_end = std::move( source.beyond_end );
number_of_elements = std::move( source.number_of_elements );
number_of_elements = source.number_of_elements;
source.nodes = nullptr;
source.beyond_end = nullptr;
return *this;
Expand Down Expand Up @@ -769,7 +764,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
return node_pointer == rh.node_pointer;
}

inline LIST_FORCE_INLINE bool operator!=( const list_iterator rh ) const noexcept {
inline LIST_FORCE_INLINE bool operator!=( const list_iterator &rh ) const noexcept {
return node_pointer != rh.node_pointer;
}

Expand Down Expand Up @@ -1215,7 +1210,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem

public:

iterator insert( const iterator it, const element_type &element ) {
iterator insert( const iterator &it, const element_type &element ) {
// ie. list is not empty
if( last_endpoint != nullptr ) {
// No erased nodes available for reuse
Expand Down Expand Up @@ -1401,7 +1396,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem

// This is almost identical to the insert implementations above with the only changes being std::forward of element parameters
template<typename... arguments>
iterator emplace( const iterator it, arguments &&... parameters ) {
iterator emplace( const iterator &it, arguments &&... parameters ) {
if( last_endpoint != nullptr ) {
if( node_allocator_pair.number_of_erased_nodes == 0 ) {
if( last_endpoint == groups.last_endpoint_group->beyond_end ) {
Expand Down Expand Up @@ -1662,7 +1657,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem

// Range insert
template <class iterator_type>
iterator insert( const iterator it,
iterator insert( const iterator &it,
typename plf_enable_if_c < !std::numeric_limits<iterator_type>::is_integer,
iterator_type >::type first, const iterator_type last ) {
if( first == last ) {
Expand All @@ -1679,7 +1674,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
}

// Initializer-list insert
inline iterator insert( const iterator it,
inline iterator insert( const iterator &it,
const std::initializer_list<element_type> &element_list ) {
// use range insert:
return insert( it, element_list.begin(), element_list.end() );
Expand All @@ -1702,7 +1697,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem

// Single erase:
// if uninitialized/invalid iterator supplied, function could generate an exception, hence no noexcept
iterator erase( const const_iterator it ) {
iterator erase( const const_iterator &it ) {
cata_assert( node_pointer_allocator_pair.total_number_of_elements != 0 );
cata_assert( it.node_pointer != nullptr );
cata_assert( it.node_pointer != end_iterator.node_pointer );
Expand Down

0 comments on commit 07fa229

Please sign in to comment.