Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
handle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "core/forward.hpp"
4
15
16#include <cstddef>
17#include <cstdint>
18#include <functional>
19
20namespace pgl {
21
22namespace detail {
23
41template <class Tag>
42class Handle {
43public:
45 using IndexType = std::uint32_t;
46
48 constexpr Handle() = default;
49
55 constexpr explicit Handle(IndexType index) : index_(index) {}
56
58 [[nodiscard]] constexpr IndexType index() const {
59 return index_;
60 }
61
63 [[nodiscard]] constexpr bool valid() const {
64 return index_ != invalidIndex;
65 }
66
68 constexpr explicit operator bool() const {
69 return valid();
70 }
71
73 constexpr bool operator==(const Handle&) const = default;
74
81 constexpr auto operator<=>(const Handle&) const = default;
82
83private:
84 static constexpr IndexType invalidIndex = ~IndexType{};
85 IndexType index_ = invalidIndex;
86};
87
88} // namespace detail
89
90} // namespace pgl
91
92namespace std {
93
95template <class Tag>
96struct hash<pgl::detail::Handle<Tag>> {
98 std::size_t operator()(const pgl::detail::Handle<Tag>& handle) const noexcept {
99 return std::hash<std::uint32_t>{}(handle.index());
100 }
101};
102
103} // namespace std
Forward declarations for core numeric and geometry types.
Definition arrangement.hpp:67