From 0996e0ee391af66cbbba108a2a324d2c98783c75 Mon Sep 17 00:00:00 2001 From: Philip Trettner <Philip.Trettner@rwth-aachen.de> Date: Sat, 21 May 2022 12:31:37 +0200 Subject: [PATCH] optional support for c++20 --- src/polymesh/cursors.hh | 13 +++++++++++-- src/polymesh/iterators.hh | 6 +++--- src/polymesh/macros.hh | 4 ++++ src/polymesh/tmp.hh | 6 ++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/polymesh/cursors.hh b/src/polymesh/cursors.hh index 17a8ee1..4c4a5e9 100644 --- a/src/polymesh/cursors.hh +++ b/src/polymesh/cursors.hh @@ -24,6 +24,10 @@ struct primitive_index bool is_invalid() const { return value < 0; } static const index_t invalid; +#ifdef POLYMESH_CPP20 + bool operator==(primitive_index const&) const = default; + auto operator<=>(primitive_index const&) const = default; +#else bool operator<(index_t const& rhs) const { return value < rhs.value; } bool operator<=(index_t const& rhs) const { return value <= rhs.value; } bool operator>(index_t const& rhs) const { return value > rhs.value; } @@ -32,6 +36,7 @@ struct primitive_index bool operator!=(index_t const& rhs) const { return value != rhs.value; } bool operator==(handle_t const& rhs) const { return value == rhs.idx.value; } bool operator!=(handle_t const& rhs) const { return value != rhs.idx.value; } +#endif explicit operator int() const { return value; } @@ -73,10 +78,14 @@ struct primitive_handle primitive_handle() = default; primitive_handle(Mesh const* mesh, index_t idx) : mesh(mesh), idx(idx) {} - bool operator==(index_t const& rhs) const { return idx == rhs; } - bool operator!=(index_t const& rhs) const { return idx != rhs; } +#ifdef POLYMESH_CPP20 + bool operator==(primitive_handle const&) const = default; +#else bool operator==(handle_t const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; } bool operator!=(handle_t const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; } +#endif + bool operator==(index_t const& rhs) const { return idx == rhs; } + bool operator!=(index_t const& rhs) const { return idx != rhs; } explicit operator int() const { return (int)idx; } operator index_t() const { return idx; } diff --git a/src/polymesh/iterators.hh b/src/polymesh/iterators.hh index 75fcac9..710931c 100644 --- a/src/polymesh/iterators.hh +++ b/src/polymesh/iterators.hh @@ -149,7 +149,7 @@ struct primitive_circulator : smart_iterator<this_t> primitive_circulator(halfedge_handle h, bool at_begin = true) : handle(h), end(h), at_begin(at_begin) {} - bool is_valid() const { return at_begin || handle != end; } + bool is_valid() const { return at_begin || handle.idx != end; } }; struct face_vertex_circulator : primitive_circulator<face_vertex_circulator> @@ -195,7 +195,7 @@ struct face_face_circulator : primitive_circulator<face_face_circulator> do // skip invalid faces { handle = handle.next(); - } while (handle != end && handle.opposite_face().is_invalid()); + } while (handle.idx != end && handle.opposite_face().is_invalid()); at_begin = false; } }; @@ -243,7 +243,7 @@ struct vertex_face_circulator : primitive_circulator<vertex_face_circulator> do // skip invalid faces { handle = handle.prev().opposite(); - } while (handle != end && handle.face().is_invalid()); + } while (handle.idx != end && handle.face().is_invalid()); at_begin = false; } }; diff --git a/src/polymesh/macros.hh b/src/polymesh/macros.hh index be8d510..9121a3b 100644 --- a/src/polymesh/macros.hh +++ b/src/polymesh/macros.hh @@ -17,6 +17,10 @@ #error "Unknown compiler" #endif +#if __cplusplus >= 202002L +#define POLYMESH_CPP20 +#endif + // ========= // compiler specific builtins diff --git a/src/polymesh/tmp.hh b/src/polymesh/tmp.hh index a0454f8..953303d 100644 --- a/src/polymesh/tmp.hh +++ b/src/polymesh/tmp.hh @@ -3,6 +3,12 @@ #include <cstddef> #include <utility> +#include <polymesh/macros.hh> + +#ifdef POLYMESH_CPP20 +#include <compare> +#endif + namespace polymesh { // small template metaprogramming -- GitLab