mirror of https://github.com/CGAL/cgal
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:
parent
2abdb4e6e4
commit
161a313109
|
|
@ -206,7 +206,13 @@ public:
|
||||||
: Constrained_triangulation_plus_2(ctp.geom_traits())
|
: Constrained_triangulation_plus_2(ctp.geom_traits())
|
||||||
{ copy_triangulation(ctp);}
|
{ 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 {}
|
~Constrained_triangulation_plus_2() override {}
|
||||||
|
|
||||||
|
|
@ -216,7 +222,14 @@ public:
|
||||||
return *this;
|
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>
|
template<class InputIterator>
|
||||||
Constrained_triangulation_plus_2(InputIterator first,
|
Constrained_triangulation_plus_2(InputIterator first,
|
||||||
|
|
|
||||||
|
|
@ -524,13 +524,29 @@ private:
|
||||||
struct Priv { // encapsulate the private members in a struct, to detect direct access to them
|
struct Priv { // encapsulate the private members in a struct, to detect direct access to them
|
||||||
Priv(Compare comp)
|
Priv(Compare comp)
|
||||||
: comp(comp)
|
: comp(comp)
|
||||||
#if CGAL_USE_BARE_STD_MAP
|
#if CGAL_USE_BARE_STD_MAP
|
||||||
, sc_to_c_map(Pair_compare(comp))
|
, sc_to_c_map(Pair_compare(comp))
|
||||||
#else
|
#else
|
||||||
, sc_to_c_map()
|
, sc_to_c_map()
|
||||||
#endif
|
#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;
|
Compare comp;
|
||||||
Sc_to_c_map sc_to_c_map;
|
Sc_to_c_map sc_to_c_map;
|
||||||
std::stack<size_type, std::vector<size_type>> free_ids;
|
std::stack<size_type, std::vector<size_type>> free_ids;
|
||||||
|
|
@ -538,10 +554,17 @@ private:
|
||||||
} priv;
|
} priv;
|
||||||
public:
|
public:
|
||||||
Polyline_constraint_hierarchy_2(const Compare& comp) : priv(comp) {}
|
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(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&&) = 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(); }
|
~Polyline_constraint_hierarchy_2() { clear(); }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
Polyline_constraint_hierarchy_2& operator=(const Polyline_constraint_hierarchy_2& ch) { return copy(ch); }
|
Polyline_constraint_hierarchy_2& operator=(const Polyline_constraint_hierarchy_2& ch) { return copy(ch); }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue