fix the move semantic of Constrained_triangulation_plus_2

The comparison functor passed to the constraints hierarchy has a
pointer to the `Constrained_triangulation_plus_2` that contains it.
That means the defaulted move constructor and move assignment operator of `Polyline_constraint_hierarchy_2` cannot be used to
implement the move constructor and move assignment operator of
`Constrained_triangulation_plus_2`.

Add a special constructor for `Polyline_constraint_hierarchy_2`, that is
usee to move the hierarchy and reassign the comparison operator.
This commit is contained in:
Laurent Rineau 2025-06-04 00:51:02 +02:00
parent 2abdb4e6e4
commit 161a313109
2 changed files with 39 additions and 3 deletions

View File

@ -206,7 +206,13 @@ public:
: Constrained_triangulation_plus_2(ctp.geom_traits())
{ copy_triangulation(ctp);}
Constrained_triangulation_plus_2(Constrained_triangulation_plus_2&&) = default;
Constrained_triangulation_plus_2(Constrained_triangulation_plus_2&& other_ctp) noexcept
: Triangulation(std::move(other_ctp))
, Constraint_hierarchy(std::move(other_ctp.hierarchy_ref()), Vertex_handle_compare(this))
{
// The hierarchy is moved, so the vertex handles are still valid.
// The triangulation is moved, so the vertex handles are still valid.
}
~Constrained_triangulation_plus_2() override {}
@ -216,7 +222,14 @@ public:
return *this;
}
Constrained_triangulation_plus_2& operator=(Constrained_triangulation_plus_2&&) = default;
Constrained_triangulation_plus_2& operator=(Constrained_triangulation_plus_2&& other_ctp) noexcept {
if (this != &other_ctp) {
static_cast<Triangulation&>(*this) = std::move(other_ctp);
static_cast<Constraint_hierarchy&>(*this) =
Constraint_hierarchy(std::move(other_ctp.hierarchy_ref()), Vertex_handle_compare(this));
}
return *this;
}
template<class InputIterator>
Constrained_triangulation_plus_2(InputIterator first,

View File

@ -524,13 +524,29 @@ private:
struct Priv { // encapsulate the private members in a struct, to detect direct access to them
Priv(Compare comp)
: comp(comp)
#if CGAL_USE_BARE_STD_MAP
#if CGAL_USE_BARE_STD_MAP
, sc_to_c_map(Pair_compare(comp))
#else
, sc_to_c_map()
#endif
{}
Priv(const Priv&) = default;
Priv(Priv&&) = default;
Priv& operator=(const Priv&) = default;
Priv& operator=(Priv&&) = default;
Priv(Priv&& other, const Compare& comp) noexcept
: comp(comp)
, sc_to_c_map(std::move(other.sc_to_c_map))
, free_ids(std::move(other.free_ids))
, constraints_set(std::move(other.constraints_set))
{
#if CGAL_USE_BARE_STD_MAP
CGAL_error_msg("This constructor cannot be used with CGAL_USE_BARE_STD_MAP");
#endif
}
Compare comp;
Sc_to_c_map sc_to_c_map;
std::stack<size_type, std::vector<size_type>> free_ids;
@ -538,10 +554,17 @@ private:
} priv;
public:
Polyline_constraint_hierarchy_2(const Compare& comp) : priv(comp) {}
Polyline_constraint_hierarchy_2(const Polyline_constraint_hierarchy_2& ch) : priv(ch.priv.comp) { copy(ch); }
Polyline_constraint_hierarchy_2(Polyline_constraint_hierarchy_2&&) = default;
Polyline_constraint_hierarchy_2(Polyline_constraint_hierarchy_2&& other, const Compare& comp) noexcept
: priv(std::move(other.priv), comp)
{}
~Polyline_constraint_hierarchy_2() { clear(); }
void clear();
Polyline_constraint_hierarchy_2& operator=(const Polyline_constraint_hierarchy_2& ch) { return copy(ch); }