summaryrefslogtreecommitdiff
path: root/src/Simplex_tree
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-08-21 13:03:33 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-08-21 13:03:33 +0000
commitad82d011d06c22ce77817ab4606bd0e15663a145 (patch)
tree61305c5af4e02eae4f36f3a4d9b1737c479f06d4 /src/Simplex_tree
parent23c6f4e26b60374d9df37445598c087ff6b52512 (diff)
Move assignment and its associated test
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/simplex_tree_fix_vincent@3819 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6fd6793b177e0a6b803adf5a710f63d8647a9288
Diffstat (limited to 'src/Simplex_tree')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h15
-rw-r--r--src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp26
2 files changed, 32 insertions, 9 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index d604f994..4759b352 100644
--- a/src/Simplex_tree/include/gudhi/Simplex_tree.h
+++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h
@@ -360,6 +360,21 @@ class Simplex_tree {
return *this;
}
+ /** \brief User-defined move assignment reproduces the whole tree structure. */
+ Simplex_tree& operator=(Simplex_tree&& simplex_source)
+ {
+#ifdef DEBUG_TRACES
+ std::cout << "move assignment" << std::endl;
+#endif // DEBUG_TRACES
+ // Self-assignment detection
+ if (&simplex_source != this) {
+ std::swap( null_vertex_, simplex_source.null_vertex_ );
+ std::swap( root_, simplex_source.root_ );
+ std::swap( filtration_vect_, simplex_source.filtration_vect_ );
+ std::swap( dimension_, simplex_source.dimension_ );
+ }
+ return *this;
+ }
/** @} */ // end constructor/destructor
private:
// Recursive deletion
diff --git a/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp
index fb3e595c..15eaf612 100644
--- a/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp
+++ b/src/Simplex_tree/test/simplex_tree_ctor_and_move_unit_test.cpp
@@ -1,11 +1,5 @@
#include <iostream>
-#include <fstream>
-#include <string>
-#include <algorithm>
-#include <utility> // std::pair, std::make_pair
-#include <cmath> // float comparison
-#include <limits>
-#include <functional> // greater
+#include <vector>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "simplex_tree_constructor_and_move"
@@ -20,6 +14,11 @@ using namespace Gudhi;
typedef boost::mpl::list<Simplex_tree<>, Simplex_tree<Simplex_tree_options_fast_persistence>> list_of_tested_variants;
+template<class SimplicialComplex>
+SimplicialComplex move_it(SimplicialComplex sc) {
+ return sc;
+}
+
BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_copy_constructor, Simplex_tree, list_of_tested_variants) {
std::cout << "********************************************************************" << std::endl;
@@ -65,12 +64,21 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_copy_constructor, Simplex_tree, list_of_te
std::cout << "********************************************************************" << std::endl;
std::cout << "TEST OF MOVE CONSTRUCTOR" << std::endl;
- Simplex_tree st5(std::move(st3));
- Simplex_tree st6(std::move(st4));
+ Simplex_tree st5(std::move(st1));
+ Simplex_tree st6(std::move(st2));
// Cross check
BOOST_CHECK(st5 == st6);
BOOST_CHECK(st == st6);
BOOST_CHECK(st5 == st);
+ std::cout << "********************************************************************" << std::endl;
+ std::cout << "TEST OF MOVE ASSIGNMENT" << std::endl;
+
+ // A swap is a copy ctor of a tmp value, then it uses move assignment
+ std::swap(st3, st4);
+ BOOST_CHECK(st3 == st4);
+ BOOST_CHECK(st == st4);
+ BOOST_CHECK(st3 == st);
+
}