From f138c6614289a2d7a808d412f85b2650f4bfeea8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 24 Sep 2019 15:06:56 +0200 Subject: [PATCH] Surface_mesh: Disable comparison of mixed index types --- .../include/CGAL/Surface_mesh/Surface_mesh.h | 82 +++++++++++++++---- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 63e3eeb4a63..0a9d4d24e4f 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -90,21 +90,6 @@ namespace CGAL { return idx_ != inf; } - /// are two indices equal? - bool operator==(const T& _rhs) const { - return idx_ == _rhs.idx_; - } - - /// are two indices different? - bool operator!=(const T& _rhs) const { - return idx_ != _rhs.idx_; - } - - /// Comparison by index. - bool operator<(const T& _rhs) const { - return idx_ < _rhs.idx_; - } - // Compatibility with OpenMesh handle size_type idx() const { return idx_; @@ -130,7 +115,7 @@ namespace CGAL { SM_Index operator+=(std::ptrdiff_t n) { idx_ = size_type(std::ptrdiff_t(idx_) + n); return *this; } - private: + protected: size_type idx_; }; @@ -141,8 +126,8 @@ namespace CGAL { return ret; } - // Implementation for Surface_mesh::Vertex_index - + + // Implementation for Surface_mesh::Vertex_index class SM_Vertex_index : public SM_Index { @@ -152,6 +137,25 @@ namespace CGAL { explicit SM_Vertex_index(size_type _idx) : SM_Index(_idx) {} + template bool operator==(const T&) const = delete; + template bool operator!=(const T&) const = delete; + template bool operator<(const T&) const = delete; + + /// are two indices equal? + bool operator==(const SM_Vertex_index& _rhs) const { + return this->idx_ == _rhs.idx_; + } + + /// are two indices different? + bool operator!=(const SM_Vertex_index& _rhs) const { + return this->idx_ != _rhs.idx_; + } + + /// Comparison by index. + bool operator<(const SM_Vertex_index& _rhs) const { + return this->idx_ < _rhs.idx_; + } + friend std::ostream& operator<<(std::ostream& os, SM_Vertex_index const& v) { @@ -177,6 +181,25 @@ namespace CGAL { SM_Halfedge_index() : SM_Index((std::numeric_limits::max)()) {} explicit SM_Halfedge_index(size_type _idx) : SM_Index(_idx) {} + + template bool operator==(const T&) const = delete; + template bool operator!=(const T&) const = delete; + template bool operator<(const T&) const = delete; + + /// are two indices equal? + bool operator==(const SM_Halfedge_index& _rhs) const { + return this->idx_ == _rhs.idx_; + } + + /// are two indices different? + bool operator!=(const SM_Halfedge_index& _rhs) const { + return this->idx_ != _rhs.idx_; + } + + /// Comparison by index. + bool operator<(const SM_Halfedge_index& _rhs) const { + return this->idx_ < _rhs.idx_; + } friend std::ostream& operator<<(std::ostream& os, SM_Halfedge_index const& h) { @@ -193,7 +216,25 @@ namespace CGAL { SM_Face_index() : SM_Index((std::numeric_limits::max)()) {} explicit SM_Face_index(size_type _idx) : SM_Index(_idx) {} + + template bool operator==(const T&) const = delete; + template bool operator!=(const T&) const = delete; + template bool operator<(const T&) const = delete; + /// are two indices equal? + bool operator==(const SM_Face_index& _rhs) const { + return this->idx_ == _rhs.idx_; + } + + /// are two indices different? + bool operator!=(const SM_Face_index& _rhs) const { + return this->idx_ != _rhs.idx_; + } + + /// Comparison by index. + bool operator<(const SM_Face_index& _rhs) const { + return this->idx_ < _rhs.idx_; + } friend std::ostream& operator<<(std::ostream& os, SM_Face_index const& f) { @@ -228,6 +269,11 @@ namespace CGAL { // returns whether the index is valid, i.e., the index is not equal to std::numeric_limits::max(). bool is_valid() const { return halfedge_.is_valid(); } + + template bool operator==(const T&) const = delete; + template bool operator!=(const T&) const = delete; + template bool operator<(const T&) const = delete; + // Are two indices equal? bool operator==(const SM_Edge_index& other) const { return (size_type)(*this) == (size_type)other; }