Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.23 AND BOOST_HEAP_USE_FILE_SET)
set(Headers
include/boost/heap/detail/ilog2.hpp
include/boost/heap/detail/heap_comparison.hpp
include/boost/heap/detail/heap_utils.hpp
include/boost/heap/detail/mutable_heap.hpp
include/boost/heap/detail/ordered_adaptor_iterator.hpp
include/boost/heap/detail/stable_heap.hpp
Expand Down
61 changes: 21 additions & 40 deletions include/boost/heap/binomial_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include <utility>

#include <boost/assert.hpp>
#include <boost/config.hpp>

#include <boost/heap/detail/heap_comparison.hpp>
#include <boost/heap/detail/heap_node.hpp>
#include <boost/heap/detail/heap_utils.hpp>
#include <boost/heap/detail/stable_heap.hpp>
#include <boost/heap/detail/tree_iterator.hpp>
#include <boost/type_traits/integral_constant.hpp>
Expand Down Expand Up @@ -66,29 +68,10 @@ struct make_binomial_heap_base
allocator_type( alloc )
{}

type( type const& rhs ) :
base_type( rhs ),
allocator_type( rhs )
{}

type( type&& rhs ) :
base_type( std::move( static_cast< base_type& >( rhs ) ) ),
allocator_type( std::move( static_cast< allocator_type& >( rhs ) ) )
{}

type& operator=( type&& rhs )
{
base_type::operator=( std::move( static_cast< base_type& >( rhs ) ) );
allocator_type::operator=( std::move( static_cast< allocator_type& >( rhs ) ) );
return *this;
}

type& operator=( type const& rhs )
{
base_type::operator=( static_cast< base_type const& >( rhs ) );
allocator_type::operator=( static_cast< allocator_type const& >( rhs ) );
return *this;
}
type( type const& rhs ) = default;
type( type&& rhs ) = default;
type& operator=( type&& rhs ) = default;
type& operator=( type const& rhs ) = default;
};
};

Expand Down Expand Up @@ -242,16 +225,8 @@ class binomial_heap :
/// \copydoc boost::heap::priority_queue::operator=(priority_queue const &)
binomial_heap& operator=( binomial_heap const& rhs )
{
if ( this == &rhs )
return *this;
clear();
size_holder::set_size( rhs.get_size() );
static_cast< super_t& >( *this ) = rhs;

if ( rhs.empty() )
top_element = nullptr;
else
clone_forest( rhs );
binomial_heap tmp( rhs );
do_swap( tmp );
return *this;
}

Expand All @@ -265,7 +240,7 @@ class binomial_heap :
}

/// \copydoc boost::heap::priority_queue::operator=(priority_queue &&)
binomial_heap& operator=( binomial_heap&& rhs )
binomial_heap& operator=( binomial_heap&& rhs ) noexcept( std::is_nothrow_move_assignable< super_t >::value )
{
clear();
super_t::operator=( std::move( rhs ) );
Expand Down Expand Up @@ -327,11 +302,11 @@ class binomial_heap :
}

/// \copydoc boost::heap::priority_queue::swap
void swap( binomial_heap& rhs )
BOOST_DEPRECATED( "Use std::swap instead" )
void swap( binomial_heap& rhs ) noexcept( std::is_nothrow_move_constructible< binomial_heap >::value
&& std::is_nothrow_move_assignable< binomial_heap >::value )
{
super_t::swap( rhs );
std::swap( top_element, rhs.top_element );
trees.swap( rhs.trees );
do_swap( rhs );
}

/// \copydoc boost::heap::priority_queue::top
Expand Down Expand Up @@ -408,7 +383,7 @@ class binomial_heap :
if ( trees.empty() ) {
stability_counter_type stability_count = super_t::get_stability_count();
size_t size = constant_time_size ? size_holder::get_size() : 0;
swap( children );
do_swap( children );
super_t::set_stability_count( stability_count );

if ( constant_time_size )
Expand Down Expand Up @@ -539,7 +514,7 @@ class binomial_heap :
return;

if ( empty() ) {
swap( rhs );
do_swap( rhs );
return;
}

Expand Down Expand Up @@ -649,6 +624,12 @@ class binomial_heap :

private:
#if !defined( BOOST_DOXYGEN_INVOKED )
void do_swap( binomial_heap& rhs ) noexcept( std::is_nothrow_move_constructible< binomial_heap >::value
&& std::is_nothrow_move_assignable< binomial_heap >::value )
{
detail::swap_via_move( *this, rhs );
}

void merge_and_clear_nodes( binomial_heap& rhs )
{
BOOST_HEAP_ASSERT( !empty() );
Expand Down
73 changes: 33 additions & 40 deletions include/boost/heap/d_ary_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include <vector>

#include <boost/assert.hpp>
#include <boost/config.hpp>

#include <boost/heap/detail/heap_comparison.hpp>
#include <boost/heap/detail/heap_utils.hpp>
#include <boost/heap/detail/mutable_heap.hpp>
#include <boost/heap/detail/ordered_adaptor_iterator.hpp>
#include <boost/heap/detail/stable_heap.hpp>
Expand Down Expand Up @@ -54,7 +56,13 @@ typedef parameter::parameters< boost::parameter::required< tag::arity >,

/* base class for d-ary heap */
template < typename T, class BoundArgs, class IndexUpdater >
class d_ary_heap : private make_heap_base< T, BoundArgs, false >::type
class d_ary_heap :
#ifndef BOOST_MSVC
private
#else
public
#endif
make_heap_base< T, BoundArgs, false >::type
{
typedef make_heap_base< T, BoundArgs, false > heap_base_maker;

Expand Down Expand Up @@ -150,29 +158,10 @@ class d_ary_heap : private make_heap_base< T, BoundArgs, false >::type
super_t( cmp )
{}

d_ary_heap( d_ary_heap const& rhs ) :
super_t( rhs ),
q_( rhs.q_ )
{}

d_ary_heap( d_ary_heap&& rhs ) :
super_t( std::move( rhs ) ),
q_( std::move( rhs.q_ ) )
{}

d_ary_heap& operator=( d_ary_heap&& rhs )
{
super_t::operator=( std::move( rhs ) );
q_ = std::move( rhs.q_ );
return *this;
}

d_ary_heap& operator=( d_ary_heap const& rhs )
{
static_cast< super_t& >( *this ) = static_cast< super_t const& >( rhs );
q_ = rhs.q_;
return *this;
}
d_ary_heap( d_ary_heap const& rhs ) = default;
d_ary_heap( d_ary_heap&& rhs ) = default;
d_ary_heap& operator=( d_ary_heap&& rhs ) = default;
d_ary_heap& operator=( d_ary_heap const& rhs ) = default;

bool empty( void ) const
{
Expand Down Expand Up @@ -233,10 +222,13 @@ class d_ary_heap : private make_heap_base< T, BoundArgs, false >::type
siftdown( 0 );
}

void swap( d_ary_heap& rhs )
void do_swap( d_ary_heap& rhs ) noexcept( std::is_nothrow_move_constructible< super_t >::value
&& std::is_nothrow_move_assignable< super_t >::value
&& std::is_nothrow_move_constructible< container_type >::value
&& std::is_nothrow_move_assignable< container_type >::value )
{
super_t::swap( rhs );
q_.swap( rhs.q_ );
super_t::do_swap( rhs );
detail::swap_via_move( q_, rhs.q_ );
}

iterator begin( void ) const
Expand Down Expand Up @@ -509,26 +501,19 @@ class d_ary_heap :
{}

/// \copydoc boost::heap::priority_queue::priority_queue(priority_queue const &)
d_ary_heap( d_ary_heap const& rhs ) :
super_t( rhs )
{}
d_ary_heap( d_ary_heap const& rhs ) = default;

/// \copydoc boost::heap::priority_queue::priority_queue(priority_queue &&)
d_ary_heap( d_ary_heap&& rhs ) :
super_t( std::move( rhs ) )
{}
d_ary_heap( d_ary_heap&& rhs ) = default;

/// \copydoc boost::heap::priority_queue::operator=(priority_queue &&)
d_ary_heap& operator=( d_ary_heap&& rhs )
{
super_t::operator=( std::move( rhs ) );
return *this;
}
d_ary_heap& operator=( d_ary_heap&& rhs ) = default;

/// \copydoc boost::heap::priority_queue::operator=(priority_queue const &)
d_ary_heap& operator=( d_ary_heap const& rhs )
{
super_t::operator=( rhs );
d_ary_heap tmp( rhs );
do_swap( tmp );
return *this;
}

Expand Down Expand Up @@ -746,9 +731,10 @@ class d_ary_heap :
}

/// \copydoc boost::heap::priority_queue::swap
BOOST_DEPRECATED( "Use std::swap instead" )
void swap( d_ary_heap& rhs )
{
super_t::swap( rhs );
do_swap( rhs );
}

/// \copydoc boost::heap::priority_queue::begin
Expand Down Expand Up @@ -798,6 +784,13 @@ class d_ary_heap :
{
return super_t::value_comp();
}

private:
void do_swap( d_ary_heap& rhs ) noexcept( std::is_nothrow_move_constructible< super_t >::value
&& std::is_nothrow_move_assignable< super_t >::value )
{
super_t::do_swap( rhs );
}
};

}} // namespace boost::heap
Expand Down
29 changes: 29 additions & 0 deletions include/boost/heap/detail/heap_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// boost heap: heap utilities
//
// Copyright (C) 2026 Tim Blechmann
//
// 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)

#ifndef BOOST_HEAP_DETAIL_HEAP_UTILS_HPP
#define BOOST_HEAP_DETAIL_HEAP_UTILS_HPP

#include <type_traits>
#include <utility>

namespace boost { namespace heap { namespace detail {


template < typename T >
inline void swap_via_move( T& lhs, T& rhs ) noexcept( std::is_nothrow_move_constructible< T >::value
&& std::is_nothrow_move_assignable< T >::value )
{
T tmp( std::move( lhs ) );
lhs = std::move( rhs );
rhs = std::move( tmp );
}

}}} // namespace boost::heap::detail

#endif /* BOOST_HEAP_DETAIL_HEAP_UTILS_HPP */
28 changes: 8 additions & 20 deletions include/boost/heap/detail/mutable_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <list>
#include <utility>

#include <boost/heap/detail/heap_utils.hpp>
#include <boost/heap/detail/ordered_adaptor_iterator.hpp>
#include <boost/iterator/iterator_adaptor.hpp>

Expand Down Expand Up @@ -77,23 +78,13 @@ class priority_queue_mutable_wrapper
public:
struct handle_type
{
handle_type() noexcept = default;

value_type& operator*() const
{
return iterator->first;
}

handle_type( void )
{}

handle_type( handle_type const& rhs ) :
iterator( rhs.iterator )
{}

handle_type& operator=( handle_type const& rhs )
{
iterator = rhs.iterator;
return *this;
}

bool operator==( handle_type const& rhs ) const
{
Expand Down Expand Up @@ -155,11 +146,8 @@ class priority_queue_mutable_wrapper

priority_queue_mutable_wrapper& operator=( priority_queue_mutable_wrapper const& rhs )
{
q_ = rhs.q_;
objects = rhs.objects;
q_.clear();
for ( typename object_list::iterator it = objects.begin(); it != objects.end(); ++it )
q_.push( it );
priority_queue_mutable_wrapper tmp( rhs );
do_swap( tmp );
return *this;
}

Expand Down Expand Up @@ -365,10 +353,10 @@ class priority_queue_mutable_wrapper
return q_.get_allocator();
}

void swap( priority_queue_mutable_wrapper& rhs )
void do_swap( priority_queue_mutable_wrapper& rhs )
{
objects.swap( rhs.objects );
q_.swap( rhs.q_ );
swap_via_move( objects, rhs.objects );
q_.do_swap( rhs.q_ );
}

const_reference top( void ) const
Expand Down
Loading