mirror of https://github.com/CGAL/cgal
Move-semantic for TDS_2
This commit is contained in:
parent
f7218dadd6
commit
aed73efb46
|
|
@ -105,8 +105,13 @@ protected:
|
|||
public:
|
||||
Triangulation_data_structure_2();
|
||||
Triangulation_data_structure_2(const Tds &tds);
|
||||
Triangulation_data_structure_2(Triangulation_data_structure_2&& tds)
|
||||
noexcept(noexcept(Face_range(std::move(tds._faces))) &&
|
||||
noexcept(Vertex_range(std::move(tds._vertices))));
|
||||
|
||||
~Triangulation_data_structure_2();
|
||||
Tds& operator= (const Tds &tds);
|
||||
Tds& operator= (Tds&& tds) noexcept(noexcept(Tds(std::move(tds))));
|
||||
void swap(Tds &tds);
|
||||
|
||||
//ACCESS FUNCTIONS
|
||||
|
|
@ -642,9 +647,6 @@ public:
|
|||
|
||||
Triangulation_default_data_structure_2(const Geom_traits& = Geom_traits())
|
||||
: Tds() {}
|
||||
|
||||
Triangulation_default_data_structure_2(const Tdds &tdds)
|
||||
: Tds(tdds) {}
|
||||
};
|
||||
|
||||
//for backward compatibility
|
||||
|
|
@ -657,8 +659,6 @@ public:
|
|||
typedef Triangulation_data_structure_using_list_2<Vb,Fb> Tdsul;
|
||||
|
||||
Triangulation_data_structure_using_list_2(): Tds() {}
|
||||
Triangulation_data_structure_using_list_2(const Tdsul &tdsul)
|
||||
: Tds(tdsul) {}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -675,6 +675,17 @@ Triangulation_data_structure_2(const Tds &tds)
|
|||
copy_tds(tds);
|
||||
}
|
||||
|
||||
template < class Vb, class Fb>
|
||||
Triangulation_data_structure_2<Vb,Fb> ::
|
||||
Triangulation_data_structure_2(Tds &&tds)
|
||||
noexcept(noexcept(Face_range(std::move(tds._faces))) &&
|
||||
noexcept(Vertex_range(std::move(tds._vertices))))
|
||||
: _dimension(std::exchange(tds._dimension, -2))
|
||||
, _faces(std::move(tds._faces))
|
||||
, _vertices(std::move(tds._vertices))
|
||||
{
|
||||
}
|
||||
|
||||
template < class Vb, class Fb>
|
||||
Triangulation_data_structure_2<Vb,Fb> ::
|
||||
~Triangulation_data_structure_2()
|
||||
|
|
@ -682,7 +693,7 @@ Triangulation_data_structure_2<Vb,Fb> ::
|
|||
clear();
|
||||
}
|
||||
|
||||
//assignement
|
||||
//copy-assignment
|
||||
template < class Vb, class Fb>
|
||||
Triangulation_data_structure_2<Vb,Fb>&
|
||||
Triangulation_data_structure_2<Vb,Fb> ::
|
||||
|
|
@ -692,6 +703,18 @@ operator= (const Tds &tds)
|
|||
return *this;
|
||||
}
|
||||
|
||||
//move-assignment
|
||||
template < class Vb, class Fb>
|
||||
Triangulation_data_structure_2<Vb,Fb>&
|
||||
Triangulation_data_structure_2<Vb,Fb> ::
|
||||
operator= (Tds &&tds) noexcept(noexcept(Tds(std::move(tds))))
|
||||
{
|
||||
_faces = std::move(tds._faces);
|
||||
_vertices = std::move(tds._vertices);
|
||||
_dimension = std::exchange(tds._dimension, -2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < class Vb, class Fb>
|
||||
void
|
||||
Triangulation_data_structure_2<Vb,Fb>::
|
||||
|
|
|
|||
|
|
@ -44,6 +44,11 @@ template <class Tds>
|
|||
void
|
||||
_test_cls_tds_2( const Tds &)
|
||||
{
|
||||
static_assert(std::is_nothrow_move_constructible<Tds>::value,
|
||||
"move cstr is missing");
|
||||
static_assert(std::is_nothrow_move_assignable<Tds>::value,
|
||||
"move assignment is missing");
|
||||
|
||||
typedef typename Tds::Vertex_range Vertex_range;
|
||||
typedef typename Tds::Face_range Face_range;
|
||||
|
||||
|
|
@ -128,6 +133,34 @@ _test_cls_tds_2( const Tds &)
|
|||
assert(tds3.dimension()== 1);
|
||||
assert(tds3.number_of_vertices() == 4);
|
||||
assert(tds3.is_valid() );
|
||||
|
||||
// Test move-constructors and move-assignments
|
||||
{
|
||||
Tds tds7 = tds3;
|
||||
Tds tds8{std::move(tds7)};
|
||||
Tds tds9 = tds3;
|
||||
Tds tds10;
|
||||
tds10 = std::move(tds9);
|
||||
Tds tds11 = Tds(tds3); // construct from a temporary
|
||||
Tds tds12 = std::move(tds11);
|
||||
|
||||
assert(tds7.is_valid());
|
||||
assert(tds8.is_valid());
|
||||
assert(tds9.is_valid());
|
||||
assert(tds10.is_valid());
|
||||
assert(tds11.is_valid());
|
||||
assert(tds12.is_valid());
|
||||
assert(tds7.dimension()==-2);
|
||||
assert(tds8.dimension()==1);
|
||||
assert(tds9.dimension()==-2);
|
||||
assert(tds10.dimension()==1);
|
||||
assert(tds11.dimension()==-2);
|
||||
assert(tds12.dimension()==1);
|
||||
tds11.~Tds();
|
||||
// check tds12 is still valid after the destruction of tds11
|
||||
assert(tds12.is_valid());
|
||||
assert(tds12.dimension()==1);
|
||||
}
|
||||
|
||||
Vertex_handle w4 = tds4.insert_first();
|
||||
Vertex_handle v4_1 = tds4.insert_second();
|
||||
|
|
|
|||
Loading…
Reference in New Issue