Skip to content
Snippets Groups Projects
Commit 0996e0ee authored by Philip Trettner's avatar Philip Trettner
Browse files

optional support for c++20

parent 98ad96fa
No related branches found
No related tags found
No related merge requests found
......@@ -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; }
......
......@@ -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;
}
};
......
......@@ -17,6 +17,10 @@
#error "Unknown compiler"
#endif
#if __cplusplus >= 202002L
#define POLYMESH_CPP20
#endif
// =========
// compiler specific builtins
......
......@@ -3,6 +3,12 @@
#include <cstddef>
#include <utility>
#include <polymesh/macros.hh>
#ifdef POLYMESH_CPP20
#include <compare>
#endif
namespace polymesh
{
// small template metaprogramming
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment