From 3b564a20f81d1da1e4b11fe1402f7aa5b246b59d Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 31 Jan 2020 11:11:19 +0100 Subject: [PATCH] Add move-semantic to TDS_3 --- .../CGAL/Triangulation_data_structure_3.h | 19 +++++++++++ .../test/TDS_3/include/CGAL/_test_cls_tds_3.h | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/TDS_3/include/CGAL/Triangulation_data_structure_3.h b/TDS_3/include/CGAL/Triangulation_data_structure_3.h index e971ee6a7db..f7b145f014d 100644 --- a/TDS_3/include/CGAL/Triangulation_data_structure_3.h +++ b/TDS_3/include/CGAL/Triangulation_data_structure_3.h @@ -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;} diff --git a/TDS_3/test/TDS_3/include/CGAL/_test_cls_tds_3.h b/TDS_3/test/TDS_3/include/CGAL/_test_cls_tds_3.h index a8b8fe41dbe..bdf03c645d8 100644 --- a/TDS_3/test/TDS_3/include/CGAL/_test_cls_tds_3.h +++ b/TDS_3/test/TDS_3/include/CGAL/_test_cls_tds_3.h @@ -26,6 +26,11 @@ template void _test_cls_tds_3( const Tds &) { + static_assert(std::is_nothrow_move_constructible::value, + "move cstr is missing"); + static_assert(std::is_nothrow_move_assignable::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;