Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : //
3 : : // Licensed under the Apache License, Version 2.0 (the "License");
4 : : // you may not use this file except in compliance with the License.
5 : : // You may obtain a copy of the License at
6 : : //
7 : : // http://www.apache.org/licenses/LICENSE-2.0
8 : : //
9 : : // Unless required by applicable law or agreed to in writing, software
10 : : // distributed under the License is distributed on an "AS IS" BASIS,
11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : // See the License for the specific language governing permissions and
13 : : // limitations under the License.
14 : :
15 : : #pragma once
16 : :
17 : : #include <cstddef>
18 : : #include <cstdint>
19 : : #include <functional>
20 : :
21 : : namespace hpactor {
22 : :
23 : : template <typename Tag, typename T = uint64_t> class Id {
24 : 2086 : T value_{};
25 : :
26 : : public:
27 : 16136323 : constexpr Id() = default;
28 : 1273133 : explicit constexpr Id(T v) : value_{v} {}
29 : :
30 : 1262745 : [[nodiscard]] constexpr T value() const noexcept {
31 : 1262745 : return value_;
32 : : }
33 : 11 : [[nodiscard]] constexpr bool valid() const noexcept {
34 : 11 : return value_ != T{};
35 : : }
36 : :
37 : 2086 : friend constexpr bool operator==(Id, Id) = default;
38 : 7 : friend constexpr bool operator!=(Id, Id) = default;
39 : : friend constexpr auto operator<=>(Id, Id) = default;
40 : : };
41 : :
42 : : } // namespace hpactor
43 : :
44 : : template <typename Tag, typename T> struct std::hash<hpactor::Id<Tag, T>> {
45 : 2560 : std::size_t operator()(hpactor::Id<Tag, T> id) const noexcept {
46 : 2560 : return std::hash<T>{}(id.value());
47 : : }
48 : : };
|