mirror of https://github.com/CGAL/cgal
Add move-semantic to TDS_3
This commit is contained in:
parent
e82ea5de96
commit
3b564a20f8
|
|
@ -230,6 +230,15 @@ public:
|
|||
copy_tds(tds);
|
||||
}
|
||||
|
||||
Triangulation_data_structure_3(Tds && tds)
|
||||
noexcept(noexcept(Cell_range(std::move(tds._cells))) &&
|
||||
noexcept(Vertex_range(std::move(tds._vertices))))
|
||||
: _dimension(std::exchange(tds._dimension, -2))
|
||||
, _cells(std::move(tds._cells))
|
||||
, _vertices(std::move(tds._vertices))
|
||||
{
|
||||
}
|
||||
|
||||
Tds & operator= (const Tds & tds)
|
||||
{
|
||||
if (&tds != this) {
|
||||
|
|
@ -239,6 +248,16 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Tds & operator= (Tds && tds)
|
||||
noexcept(noexcept(Tds(std::move(tds))))
|
||||
{
|
||||
Tds tmp(std::move(tds));
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Triangulation_data_structure_3() = default; // for the rule-of-five
|
||||
|
||||
size_type number_of_vertices() const { return vertices().size(); }
|
||||
|
||||
int dimension() const {return _dimension;}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ template <class Tds>
|
|||
void
|
||||
_test_cls_tds_3( 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::Cell_range Cell_range;
|
||||
|
||||
|
|
@ -115,6 +120,34 @@ _test_cls_tds_3( const Tds &)
|
|||
std::cout << "ok" << std::endl;
|
||||
assert(tds6.is_valid());
|
||||
|
||||
// Test move-constructors and move-assignments
|
||||
{
|
||||
Tds tds7 = tds5;
|
||||
Tds tds8{std::move(tds7)};
|
||||
Tds tds9 = tds5;
|
||||
Tds tds10;
|
||||
tds10 = std::move(tds9);
|
||||
Tds tds11 = Tds(tds5); // 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()==2);
|
||||
assert(tds9.dimension()==-2);
|
||||
assert(tds10.dimension()==2);
|
||||
assert(tds11.dimension()==-2);
|
||||
assert(tds12.dimension()==2);
|
||||
tds11.~Tds();
|
||||
// check tds12 is still valid after the destruction of tds11
|
||||
assert(tds12.is_valid());
|
||||
assert(tds12.dimension()==2);
|
||||
}
|
||||
|
||||
std::cout << " Insert are tested in test_triangulation_3 " << std::endl;
|
||||
|
||||
std::cout << " Iterator and circulator are tested in test_triangulation_3 " << std::endl;
|
||||
|
|
|
|||
Loading…
Reference in New Issue