Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
pos-idx.hh
Go to the documentation of this file.
1#pragma once
3
4#include <cinttypes>
5#include <functional>
6
7namespace nix {
8
9class PosIdx
10{
11 friend struct LazyPosAccessors;
12 friend class PosTable;
13 friend class std::hash<PosIdx>;
14
15private:
16 uint32_t id;
17
18 constexpr explicit PosIdx(uint32_t id)
19 : id(id)
20 {
21 }
22
23public:
24 constexpr PosIdx()
25 : id(0)
26 {
27 }
28
29 explicit operator bool() const
30 {
31 return id > 0;
32 }
33
34 auto operator<=>(const PosIdx other) const
35 {
36 return id <=> other.id;
37 }
38
39 bool operator==(const PosIdx other) const
40 {
41 return id == other.id;
42 }
43
44 size_t hash() const noexcept
45 {
46 return std::hash<uint32_t>{}(id);
47 }
48};
49
50inline PosIdx noPos = {};
51
52} // namespace nix
53
54namespace std {
55
56template<>
57struct hash<nix::PosIdx>
58{
59 std::size_t operator()(nix::PosIdx pos) const noexcept
60 {
61 return pos.hash();
62 }
63};
64
65} // namespace std
Definition pos-idx.hh:10